In Unix, just about everything (including a network socket) is a file.
Extract email addresses from a file.
gawk ‘BEGIN { RS = “[.@]*[^-0-9A-Za-z_.@]+[.@]*” } /@/’
Find the version of an Oracle database
Using SQLPlus, issue one of these two commands:
SELECT * FROM SYS.V_$VERSION;
select * from v$version where banner like Oracle%;
Run a command as user "x" in a shell script
Ever need to run a command as a specific user? Many Oracle commands require you to become the “oracle” user to make use of them.
To do this in a script, simply define your Oracle variables and use the “su” command. Here’s some example code:
ORA_HOME=/d01/app/oracle/product/9.2.0
ORA_OWNER=oracle
su – $ORA_OWNER -c “$ORA_HOME/bin/lsnrctl start listener_rmdyd1”
su – $ORA_OWNER -c “$ORA_HOME/bin/lsnrctl start listener_hbstgu1”
FSCK an Oracle OCFS filesystem
With the filesystem unmounted:
$ fsck.ocfs /dev/sda1
Remove OSS Java
The open source variant of Java is usually installed by default. If you don’t want/need it, remove it with the following commands:
$ rpm -e java-1.4.2-gcj-compat-1.4.2.0-27jpp
$ rpm -e gcc-java
Record your actions
Just run the “script” command before you start typing anything. It will record all the actions you take at the command line in a readable file called ‘typescript’ in your current directory.
Clear a log file without deleting it
Need to clear out a log file to get rid of the “noise” in it? I do that often when tracking down a problem. However, deleting it usually means restarting the service that spawned it, which is not always possible (on a production server). The solution is to use redirection and the so-called “bit bucket” to get this done.
You clear the contents of a file (by sending it null data), but keep the file itself. Here’s how:
Lets say we are not happy that the “lastlog” file has grown to 19 megabytes in size.
# ls -ltr lastlog
-r——– 1 root root 19M Feb 6 12:34 lastlog
So we fill up the lastlog file with nothingness from /dev/null:
# cat /dev/null > lastlog
Ahhh, now lastlog is a good size!
# ls -ltr lastlog
-r——– 1 root root 0 Feb 6 12:34 lastlog
List files by size
ls -lSr
Semaphore. Defined.
Semaphores can best be described as counters which are used to provide synchronization between processes or between threads within a process for shared resources like shared memories.