Different Types of Shells to Declare

#!/usr/bin/sh OR #!/bin/sh Declares a Bourne shell
#!/usr/bin/ksh OR #!/bin/ksh Declares a Korn shell
#!/usr/bin/csh OR #!/bin/csh Declares a C shell
#!/usr/bin/bash OR #!/bin/bash Declares a Bourne-Again shell

Linux Commands


As you know, the mv command renames files. For example,

$ mv oldname newname
renames the file oldname to newname. However, what if you don’t know the filenames yet? The rename command comes in really handy here.

rename .log .log.‘date +%F-%H:%M:%S‘ *

replaces all files with the extension .log with .log.. So sqlnet.log becomes sqlnet.log.2006-09-12-23:26:28.

alias and unalias

Suppose you want to check the ORACLE_SID environment variable set in your shell. You will have to type:


As a DBA or a developer, you frequently use this command and will quickly become tired of typing the entire 16 characters. Is there is a simpler way?

There is: the alias command. With this approach you can create a short alias, such as “os”, to represent the entire command:

alias os=’echo $ORACLE_HOME’

Now whenever you want to check the ORACLE_SID, you just type “os” (without the quotes) and Linux executes the aliased command.

However, if you log out and log back in, the alias is gone and you have to enter the alias command again. To eliminate this step, all you have to do is to put the command in your shell’s profile file. For bash, the file is .bash_profile (note the period before the file name, that’s part of the file’s name) in your home directory. For bourne and korn shells, it’s .profile, and for c-shell, .chsrc.

You can create an alias in any name. For instance, I always create an alias for the command rm as rm -i, which makes the rm command interactive.

alias rm=’rm -i’

Whenever I issue an rm command, Linux prompts me for confirmation, and unless I provide “y”, it doesn’t remove the file—thus I am protected form accidentally removing an important file. I use the same for mv (for moving the file to a new name), which prevents accidental overwriting of existing files, and cp (for copying the file).

Here is a list of some very useful aliases I like to define:

alias bdump=’cd $ORACLE_BASE/admin/$ORACLE_SID/bdump’
alias l=’ls -d .* –color=tty’
alias ll=’ls -l –color=tty’
alias mv=’mv -i’
alias oh=’cd $ORACLE_HOME’
alias os=’echo $ORACLE_SID’
alias rm=’rm -i’
alias tns=’cd $ORACLE_HOME/network/admin’

Painless Changes to Owner, Group, and Permissions

# ls -l
total 8
-rw-r–r– 1 test users 70 Aug 4 04:02 file1
-rwxr-xr-x 1 oracle dba 132 Aug 4 04:02 file2
-rwxr-xr-x 1 oracle dba 132 Aug 4 04:02 file3
-rwxr-xr-x 1 oracle dba 132 Aug 4 04:02 file4
-rwxr-xr-x 1 oracle dba 132 Aug 4 04:02 file5
-rwxr-xr-x 1 oracle dba 132 Aug 4 04:02 file6

and you need to change the permissions of all the files to match those of file1. Sure, you could issue chmod 644 * to make that change—but what if you are writing a script to do that, and you don’t know the permissions beforehand? Or, perhaps you are making several permission changes and based on many different files and you find it infeasible to go though the permissions of each of those and modify accordingly.

A better approach is to make the permissions similar to those of another file. This command makes the permissions of file2 the same as file1:

chmod –reference file1 file2

Now if you check:

# ls -l file[12]
total 8
-rw-r–r– 1 test users 70 Aug 4 04:02 file1
-rw-r–r– 1 oracle dba 132 Aug 4 04:02 file2

The file2 permissions were changed exactly as in file1. You didn’t need to get the permissions of file1 first.

You can also use the same trick in group membership in files. To make the group of file2 the same as file1, you would issue:

# chgrp –reference file1 file2
# ls -l file[12]
-rw-r–r– 1 test users 70 Aug 4 04:02 file1
-rw-r–r– 1 oracle users 132 Aug 4 04:02 file2

Of course, what works for changing groups will work for owner as well. Here is how you can use the same trick for an ownership change. If permissions are like this:

# ls -l file[12]
-rw-r–r– 1 test users 70 Aug 4 04:02 file1
-rw-r–r– 1 oracle dba 132 Aug 4 04:02 file2

You can change the ownership like this:

# chown –reference file1 file2
# ls -l file[12]
-rw-r–r– 1 test users 70 Aug 4 04:02 file1
-rw-r–r– 1 test users 132 Aug 4 04:02 file2

Note that the group as well as the owner have changed.

UNIX COMMANDS- AIX Command Crib Sheet

oslevel Returns operating system level

whence (program) Returns full path of program
whereis (program) Returms full path of program

what (program) Displays identifying info from the executable
like version number, when compiled.

lslpp -L all list all installed software
lslpp -L (program set name) Check if software installed
lslpp -f Lists filesets vs packages
lslpp -ha Lists installation history of filesets

instfix -ik (fix number eg IX66617) Checks id fix is installed
instfix -ik 4330-02_AIX_ML

compress -c file.txt > file.Z Create a compressed file.

uuencode (infile) (extract-file-name) > (output file)
Converts a binary file to an ASCII file for transfer by modem or email

uudecode (encoded file)
Extracts a binary file from encoded file and calls it the extract-file-name

examples :-

uuencode maymap maymap > maymap.enc
uuencode maymap.enc

od -c /tmp Displays contents of the /tmp directory file
ls -i Lists files with their inode numbers
echo * Lists files, can be used if ls is corrupt/missing

alog -o -t boot View the boot log

chtz (timezone eg GMT0BST) Changes the timezone in /etc/environment file
chlang (language eg En_GB) Changes the language in /etc/environment file

ar -v -t (archive file) List contents of an archive
ar -v -x (archive file) Extracts the archive
ar -v -t /usr/lib/libC-r.a Lists contents of the libC_r.a library

find /source -print | cpio -pdm /target
Copying directories using cpio, creates /target/source directory.

dump -nTv (binary executable) Displays the contents of an executable file

dump -c Displays string information
dump -o Displays object file headers
dump -l Displays line numbers
dump -s Displays the text section

snap -ao /dev/rmt0 Create a snapshot onto tape
snap -ad (directory) Create a snapshot into a named directory other
than the default (/tmp/ibmsupt)

/usr/dt/bin/dtconfig -d Disables desktop logins
/usr/dt/bin/dtconfig -e Enables desktop logins
/var/dt/Xpid PID of the dtlogin process


tty Displays what the tty/pty number of the terminal is.

termdef reports the termtype setup in smit for the tty port
that termdef is run on.

chdev -l (device eg tty1) -a term=vt100 Sets tty to a vt100 terminal type

penable tty0 adds getty line into /etc/inittab for tty0 and starts getty
pdisable tty0 disables the getty line and disables getty

penable / pdisable -a option is for all

stty erase ^? Set backspace key for vt100 terminals
stty erase ^H Set backspace key for wyse50 terminals

lscons Displays the console device
chcons -a login=enable (device eg /dev/tty1) Changes the console device

Create ttys on ports 0 to 7 on adapter sa2 :-

for i in 0 1 2 3 4 5 6 7
mkdev -c tty1 -t tty -s rs232 -p sa2 -w$i -a login=enable -a term=vt100

portmir -t /dev/tty0 Mirror current terminal onto /dev/tty0
portmir -o Turns off port mirroring


host (ip or hostname) Resolves a hostname / ip address

hostname Displays hostname
hostname (hostname) Sets the hostname until next reboot

chdev -l (device name) -a hostname=(hostname) Changes hostname permanently
chdev -l inet0 -a hostname=thomas

ifconfig (device name) Displays network card settings
ifconfig (device name) up Turns on network card
ifconfig (device name) down Turns off network card
ifconfig (device name) detach Removes the network card from the
network interface list
ifconfig en0 inet netmask up

ifconfig lo0 alias Create alias ip address for loopback

route (add/delete) (-net/-host) (destination) (gateway)
Adds or deletes routes to other networks or hosts, does not update
the ODM database and will be lost at reboot.
route add -net

lsattr -EHl inet0 Displays routes set in ODM and hostname
odmget -q “name=inet0” CuAt Displays routes set in ODM and hostname

refresh -s inetd Refresh inetd after changes to inetd.conf
kill -1 (inetd PID) Refresh inetd after changes to inted.conf

netstat -i Displays interface statistics
entstat -d (ethernet adapter eg en0) Displays ethernet statistics

arp -a Displays ip to mac address table from arp cache

no -a Displays network options use -o to set individual options or
-d to set individual options to default.
no -o option=value (this value is reset at reboot)
no -o “ipforwarding=1”

traceroute (name or ipaddress) Displays all the hops from source to
destination supplied.

ping -R (name or ipaddress) Same as traceroute except repeats.


exportfs Lists all exported filesystems

exportfs -a Exports all fs’s in /etc/exports file

exportfs -u (filesystem) Un-exports a filesystem

mknfs Configures and starts NFS services

rmnfs Stops and un-configures NFS services

mknfsexp -d /directory Creates an NFS export directory

mknfsmnt Creates an NFS mount directory

mount hostname:/filesystem /mount-point Mount an NFS filesystem

nfso -a Display NFS Options
nfso -o option=value Set an NFS Option
nfso -o nfs_use_reserved_port=1



mkszfile -f Creates /image.data file (4.x onwards)
mkszfile -X Creates /fs.size file (3.x)

mksysb (device eg /dev/rmt0)


find (filesystem) -print | cpio -ocv > (filename or device)

eg find ./usr/ -print | cpio -ocv > /dev/rmt0


cpio -ict < (filename or device) | more Lists archive
cpio -icdv < (filename or device)
cpio -icdv < (filename or device) ("files or directories to restore")

eg cpio -icdv < /dev/rmt0 "tcpip/*" Restore directory and contents
cpio -icdv new.filename
Strips out ^M characters from ascii files that have been transferred as binary.
To enter crontrol characters type ctrl v then ctrl ? where ? is whatever
ctrl character you need.


lscfg lists all installed devices
lscfg -v lists all installed devices in detail
lscfg -vl (device name) lists device details

bootinfo -b reports last device the system booted from
bootinfo -k reports keyswitch position
1=secure, 2=service, 3=normal

bootinfo -r reports amount of memory (/ by 1024)
bootinfo -s (disk device) reports size of disk drive
bootinfo -T reports type of machine ie rspc

lsattr -El sys0 -a realmem reports amount of useable memory

mknod (device) c (major no) (minor no) Creates a /dev/ device file.
mknod /dev/null1 c 2 3

lsdev -C lists all customised devices ie installed
lsdev -P lists all pre-defined devices ie supported
lsdev -(C or P) -c (class) -t (type) -s (subtype)

chdev -l (device) -a (attribute)=(new value) Change a device attribute
chdev -l sys0 -a maxuproc=80

lsattr -EH -l (device) -D Lists the defaults in the pre-defined db
lsattr -EH -l sys0 -a modelname

rmdev -l (device) Change device state from available to defined
rmdev -l (device) -d Delete the device
rmdev -l (device) -SR S stops device, R unconfigures child devices

lsresource -l (device) Displays bus resource attributes of a device.

Power Management (PCI machines)

pmctrl -a Displays the Power Management state

rmdev -l pmc0 Unconfigure Power Management
mkdev -l pmc0 Configure Power Management


rmt0.x where x = A + B + C

A = density 0 = high 4 = low
B = retension 0 = no 2 = yes
C = rewind 0 = no 1 = yes

tctl -f (tape device) fsf (No) Skips forward (No) tape markers
tctl -f (tape device) bsf (No) Skips back (No) tape markers
tctl -f (tape device) rewind Rewind the tape
tctl -f (tape device) offline Eject the tape
tctl -f (tape device) status Show status of tape drive

chdev -l rmt0 -a block_size=512 changes block size to 512 bytes
(4mm = 1024, 8mm = variable but
1024 recommended)

bootinfo -e answer of 1 = machine can boot from a tape drive
answer of 0 = machine CANNOT boot from tape drive

diag -c -d (tape device) Hardware reset a tape drive.

tapechk (No of files) Checks Number of files on tape.

(filename) Output crontab entrys to a file
crontab (filename) Enter a crontab from a file
crontab -r Removes all crontab entrys
crontab -v Displays crontab submission time.

/var/adm/cron/cron.allow File containing users allowed crontab use.
/var/adm/cron/cron.deny File containing users denied crontab use.
/var/adm/cron/crontab Directory containing users crontab entries.

at (now + 2 minutes, 13:05, etc) {return} Schedule a job using at
Command or schell script {return}

at -l
atq Lists out jobs scheduled to run via at command

at -r (at job No)
atrm (at job No) Removes an at job scheduled to run.

/var/adm/cron/at.allow File containing users allowed at use.
/var/adm/cron/at.deny File containing users denied at use.
/var/adm/cron/atjobs Directory containing users at entries.


groups Lists out the groups that the user is a member of
setgroups Shows user and process groups

chmod abcd (filename) Changes files/directory permissions

Where a is (4 SUID) + (2 SGID) + (1 SVTX)
b is (4 read) + (2 write) + (1 execute) permissions for owner
c is (4 read) + (2 write) + (1 execute) permissions for group
d is (4 read) + (2 write) + (1 execute) permissions for others

-rwxrwxrwx -rwxrwxrwx -rwxrwxrwx
||| ||| |||
– – –
| | |
Owner Group Others

-rwSrwxrwx = SUID -rwxrwSrwx = SGID drwxrwxrwt = SVTX

chown (new owner) (filename) Changes file/directory owners
chgrp (new group) (filename) Changes file/directory groups

chown (new owner).(new group) (filename) Do both !!!

umask Displays umask settings
umask abc Changes users umask settings

where ( 7 – a = new file read permissions)
( 7 – b = new file write permissions)
( 7 – c = new file execute permissions)

eg umask 022 = new file permissions of 755 = read write and execute for owner
read —– and execute for group
read —– and execute for other

mrgpwd > file.txt Creates a standard password file in file.txt

passwd Change current user password

pwdadm (username) Change a users password

pwdck -t ALL Verifies the correctness of local authentication

lsgroup ALL Lists all groups on the system
mkgroup (new group) Creates a group
chgroup (attribute) (group) Change a group attribute
rmgroup (group) Removes a group


passwd -f Change current users gecos (user description)
passwd -s Change current users shell

chfn (username) Changes users gecos
chsh (username) (shell) Changes users shell

env Displays values of environment variables

id Displays current user’s uid and gid details
id (user) Displays user uid and gid details

whoami Displays current user details
who am i (or who -m)

who Displays details of all users currently logged in.
who -b Displays system reboot time

uptime Displays number of users logged in, time since last
reboot, and the machine load averages.

lslicense Displays number of current user licensese
chlicense -u (number) Changes the number of user licenses

lsuser ALL Lists all users details
lsuser (username) Lists details for user
lsuser -a(attribute) (username or ALL) Lists user attributes
lsuser -a home ALL

mkuser -a(attributes) (newuser) Add a new user

chuser (attributes) (user) Change a user
chuser login=false (user) Lock a user account

rmuser -p (user) Removes a user and all entries in security files

usrck -t ALL Checks all the user entires are okay.

fuser -u (logical volume) Displays processes using the files in that LV

lsattr -D -l sys0 -a maxuproc Displays max number of processes per user
chdev -l sys0 -a maxuproc=(number) Changes max number of processes per user


ruser -a -f (user) Adds entry into /etc/ftpusers file
ruser -a -p (host) Adds entry into /etc/host.lpd file
ruser -a -r (host) Adds entry into /etc/hosts.equiv file

ruser -d -f (user) Deletes entry in /etc/ftpusers file
ruser -d -p (host) Deletes entry in /etc/host.lpd file
ruser -d -r (host) Deletes entry in /etc/hosts.equiv file

ruser -s -F Shows all entries in /etc/ftpusers file
ruser -s -P Shows all entries in /etc/host.lpd file
ruser -s -R Shows all entries in /etc/hosts.equiv file

ruser -X -F Deletes all entries in /etc/ftpusers file
ruser -X -P Deletes all entries in /etc/host.lpd file
ruser -X -R Deletes all entries in /etc/hosts.equiv file


telinit S Switches to single user mode.
telinit 2 Switches to multi user mode.
telinit q Re-examines /etc/inittab

lsitab -a Lists all entries in inittab
lsitab (ident eg tty1) Lists the tty1 entry in inittab

mkitab (“details”) Creates a new inittab entry
chitab (“details”) Ammends an existing inittab entry

rmitab (ident eg tty1) Removes an inittab entry.

chitab “tty1:2:respawn:/usr/bin/getty /dev/tty1”


odmget -q “name=lp1” CuDv |more Gets lp1 info from pre-defined database.

odmget -q “name-lp1” CuAt |more Gets lp1 info from customised database.

odmdelete -o CuAt -q “name=lp1” Deletes lp1 info from customised db.

odmget -q “name=lp1” CuAt > lp1.CuAt Export ODM info to text file.
odmadd < lp1.CuAt Import ODM info from text file.


/usr/lib/errdemon -l Displays errorlog attributes.
/usr/lib/errdemon Starts error logging.
/usr/lib/errstop Stops error logging.

errpt Displays summary errorlog report.
errpt -a Displays detailed errorlog report.
errpt -j (identifier) Displays singe errorlog report.

Note : errorlog classes are H=Hardware S=Software O=Information V=Undetermined

errclear (days) Deletes all error classes in the errorlog.
errclear -d (class) (days) Deletes all error class entries in errlog.

Note : The errclear command will delete all entries older than the numbers of
days specified in the days paramenter. To delete ALL entries used 0.

errlogger "message up to 230 chrs"
Enters an operator notifaction message into the errorlog.


vmstat (drive) (interval) (count) Reports virtual memory statistics.
vmstat hdisk0 5 20

vmstat -s Diplays number of paging events since system start.
vmstat -f Diplays number of forks since system start.
vmstat -i Diplays number of interupts by device since system start.

iostat (drive) (interval) (count) Reports i/o and cpu statistics.
iostat hdisk0 5 20

iostat -d (drive) (interval) (count) Limits report to drive statistics.
iostat -t (interval) (count) Limits report to tty statistics.

sar -u -P ALL 10 10 Displays %usr %sys %wio %idle for all processors


dosdir Reads directory listing of a diskette
dosdir (directory) Reads directory listing of a named directory

dosread -D/dev/fd0 C41.TXT c41.txt Gets C41.TXT from diskette drive fd0

dosread -D/dev/fd0 DIRECTORY/C41.TXT c41.txt
(-D option can be dropped if using fd0)

doswrite -D/dev/fd0 (unixfile) (dosfile) Writes a file to diskette

dosdel (dosfile) Deletes a dos file on diskette

dosformat Formats the diskette


sendmail -bi Creates new aliase db from /etc/aliase file.

sendmail -bp Displays the contents of the mail queue

sendmail -q Processe the sendmail queue NOW

sendmail -bt -d0.4 < /dev/null
Prints out sendmail version, compile defines and system information

refresh -s sendmail Restart sendmail
kill -l (sendmail PID)


dsh (command) Runs the command on all the nodes

Efence Diplays which node are currently fenced
Efence (node number) Fences the node

Eunfence (node number) Unfences the node

Estart Starts the switch

spmon -q Starts SP monitor in gui
spmon -d -G Diag info, lists LED and switch info for all nodes
spmon -L frame1/node3 Displays LED for node 3 in frame 1

spmon -p off frame1/node3 Powers off the node
spmon -p on frame1/node3 Powers on the node

spled Diplays all the nodes LED's in a updating gui

s1term -w (frame number) (node number) Opens serial terminal (read and write)
s1term (frame number) (node number) Opens serial terminal (read only)

Example :-

s1term 1 1 Opens a serial terminal to console port on frame 1 node 1
which is read only. When rebooting a node use read only.

splstdata -e Lists site environment database information
-d Displays df command from each node
-n Lists node configuration
-h Diplays lscfg command from each node
-s Lists switch node information
-b Lists boot/installation information
-a Lists LAN database information
-i Displays netstat -in command from each node

ORA-27054: NFS file system where the file is created or resides is not mounted with correct options

NFS Mount Options

You must mount NFS volumes used for storing database files with special mount options on the host where the database server is running. When mounting an NFS file system, Oracle recommends that you use the same mount point options that your NAS vendor used when certifying the device. Refer to your device documentation or contact your vendor for information about recommended mount-point options.

In general, most vendors recommend that you use the NFS mount options listed in the following table.

Option Requirement Description
hard Mandatory Generate a hard mount of the NFS file system. If the connection to the server fails or is temporarily lost, connection attempts are made until the NAS device responds.
bg Optional Try to connect in the background if connection fails.
tcp Optional Use the TCP protocol rather than UDP. TCP is more reliable than UDP.
nfsvers=3 Optional Use NFS version 3. Oracle recommends that you use NFS version 3 where available, unless the performance of version 2 is higher.
suid Optional Allow clients to run executables with SUID enabled. This option is required for Oracle software mount points.
rsize Mandatory The number of bytes used when reading from the NAS device. This value should be set to the maximum database block size supported by this platform. A value of 8192 is often recommended for NFS version 2 and 32768 is often recommended for NFS version 3.
wsize Mandatory The number of bytes used when writing to the NAS device. This value should be set to the maximum database block size supported by this platform. A value of 8192 is often recommended for NFS version 2 and 32768 is often recommended for NFS version 3.
nointr (or intr) Optional Do not allow (or allow) keyboard interrupts to kill a process that is hung while waiting for a response on a hard-mounted file system.

Note: Different vendors have different recommendations about this option. Contact your vendor for advice.

actime=0 or noac Mandatory Disable attribute caching.

Note: You must specify this option for NFS file systems where you want to install the software. If you do not use this option, Oracle Universal Installer will not install the software in the directory that you specify.

The mandatory mount options comprise the minimum set of mount options that you must use while mounting the NFS volumes. These mount options are essential to protect the integrity of the data and to prevent any database corruption. Failure to use these mount options may result in the generation of file access errors. Refer to your operating system or NAS device documentation for more information about the specific options supported on your platform.

For AIX:

For HP-UX:


DBSTART script does not work with KSH shell and it gives the following error:

/base/oracle/product/V10.2.0.3/bin/dbstart[89]: test: argument expected
Failed to auto-start Oracle Net Listener using /bin/tnslsnr
Processing Database instance “DGED00”: log file

This happens when running dbstart as a part of the startup procedures. It can be reproduced using the command line as follows:
su – oracle -c “${ORACLE_HOME}/bin/dbstart”

1/ The result of this command is :
/base/oracle/product/V10.2.0.3/bin/dbstart[89]: test: argument expected
Failed to auto-start Oracle Net Listener using /bin/tnslsnr
Processing Database instance “DGED00”: log file

2/ The content of startup.log is :
startinst[79]: /base/oracle/product/V10.2.0.3/dbs/spfileDGED00.ora: unknown
test operator
logger: illegal option — s
Usage: logger [ -t tag ] [ -p pri ] [ -i ] [ -f file ] [message …]
logger: illegal option — s
Usage: logger [ -t tag ] [ -p pri ] [ -i ] [ -f file ] [message …]
logger: illegal option — s
Usage: logger [ -t tag ] [ -p pri ] [ -i ] [ -f file ] [message …]


In the dbstart script, there is a test on existence of some files :

if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then
When changing it to be (as in version, it works fine:
if [ -f $SPFILE -o -f $SPFILE1 -o -f $PFILE ] ; then

ksh on HPIA does not support test -e argument and so fails.
Passing over to DDR as generic as maybe the generic code
could use a more widely supported option such as -r
(as -e will show that a file exists even if it cannot be read
but -r will only short the file exists if it can be read
and -r should honor symbolic links).

vmstat command

The first tool to use is the vmstat command, which quickly provides compact information about various system resources and their related performance problems.
The vmstat command reports statistics about kernel threads in the run and wait queue, memory, paging, disks, interrupts, system calls, context switches, and CPU activity. The reported CPU activity is a percentage breakdown of user mode, system mode, idle time, and waits for disk I/O.
Note: If the vmstat command is used without any options or only with the interval and optionally, the count parameter, such as vmstat 2 10; then the first line of numbers is an average since system reboot.
As a CPU monitor, the vmstat command is superior to the iostat command in that its one-line-per-report output is easier to scan as it scrolls and there is less overhead involved if there are a lot of disks attached to the system. The following example can help you identify situations in which a program has run away or is too CPU-intensive to run in a multiuser environment.

# vmstat 2
kthr memory page faults cpu
—– ———– ———————— ———— ———–
r b avm fre re pi po fr sr cy in sy cs us sy id wa
1 0 22478 1677 0 0 0 0 0 0 188 1380 157 57 32 0 10
1 0 22506 1609 0 0 0 0 0 0 214 1476 186 48 37 0 16
0 0 22498 1582 0 0 0 0 0 0 248 1470 226 55 36 0 9

2 0 22534 1465 0 0 0 0 0 0 238 903 239 77 23 0 0
2 0 22534 1445 0 0 0 0 0 0 209 1142 205 72 28 0 0
2 0 22534 1426 0 0 0 0 0 0 189 1220 212 74 26 0 0
3 0 22534 1410 0 0 0 0 0 0 255 1704 268 70 30 0 0
2 1 22557 1365 0 0 0 0 0 0 383 977 216 72 28 0 0

2 0 22541 1356 0 0 0 0 0 0 237 1418 209 63 33 0 4
1 0 22524 1350 0 0 0 0 0 0 241 1348 179 52 32 0 16
1 0 22546 1293 0 0 0 0 0 0 217 1473 180 51 35 0 14

This output shows the effect of introducing a program in a tight loop to a busy multiuser system. The first three reports (the summary has been removed) show the system balanced at 50-55 percent user, 30-35 percent system, and 10-15 percent I/O wait. When the looping program begins, all available CPU cycles are consumed. Because the looping program does no I/O, it can absorb all of the cycles previously unused because of I/O wait. Worse, it represents a process that is always ready to take over the CPU when a useful process relinquishes it. Because the looping program has a priority equal to that of all other foreground processes, it will not necessarily have to give up the CPU when another process becomes dispatchable. The program runs for about 10 seconds (five reports), and then the activity reported by the vmstat command returns to a more normal pattern.

Optimum use would have the CPU working 100 percent of the time. This holds true in the case of a single-user system with no need to share the CPU. Generally, if us + sy time is below 90 percent, a single-user system is not considered CPU constrained. However, if us + sy time on a multiuser system exceeds 80 percent, the processes may spend time waiting in the run queue. Response time and throughput might suffer.

To check if the CPU is the bottleneck, consider the four cpu columns and the two kthr (kernel threads) columns in the vmstat report. It may also be worthwhile looking at the faults column:

* cpu

Percentage breakdown of CPU time usage during the interval. The cpu columns are as follows:
o us

The us column shows the percent of CPU time spent in user mode. A UNIX® process can execute in either user mode or system (kernel) mode. When in user mode, a process executes within its application code and does not require kernel resources to perform computations, manage memory, or set variables.
o sy

The sy column details the percentage of time the CPU was executing a process in system mode. This includes CPU resource consumed by kernel processes (kprocs) and others that need access to kernel resources. If a process needs kernel resources, it must execute a system call and is thereby switched to system mode to make that resource available. For example, reading or writing of a file requires kernel resources to open the file, seek a specific location, and read or write data, unless memory mapped files are used.
o id

The id column shows the percentage of time which the CPU is idle, or waiting, without pending local disk I/O. If there are no threads available for execution (the run queue is empty), the system dispatches a thread called wait, which is also known as the idle kproc. On an SMP system, one wait thread per processor can be dispatched. The report generated by the ps command (with the -k or -g 0 option) identifies this as kproc or wait. If the ps report shows a high aggregate time for this thread, it means there were significant periods of time when no other thread was ready to run or waiting to be executed on the CPU. The system was therefore mostly idle and waiting for new tasks.
o wa

The wa column details the percentage of time the CPU was idle with pending local disk I/O and NFS-mounted disks. If there is at least one outstanding I/O to a disk when wait is running, the time is classified as waiting for I/O. Unless asynchronous I/O is being used by the process, an I/O request to disk causes the calling process to block (or sleep) until the request has been completed. Once an I/O request for a process completes, it is placed on the run queue. If the I/Os were completing faster, more CPU time could be used.

A wa value over 25 percent could indicate that the disk subsystem might not be balanced properly, or it might be the result of a disk-intensive workload.

For information on the change made to wa, see Wait I/O time reporting.
* kthr

Number of kernel threads in various queues averaged per second over the sampling interval. The kthr columns are as follows:
o r

Average number of kernel threads that are runnable, which includes threads that are running and threads that are waiting for the CPU. If this number is greater than the number of CPUs, there is at least one thread waiting for a CPU and the more threads there are waiting for CPUs, the greater the likelihood of a performance impact.
o b

Average number of kernel threads in the VMM wait queue per second. This includes threads that are waiting on filesystem I/O or threads that have been suspended due to memory load control.

If processes are suspended due to memory load control, the blocked column (b) in the vmstat report indicates the increase in the number of threads rather than the run queue.
o p

For vmstat -I The number of threads waiting on I/Os to raw devices per second. Threads waiting on I/Os to filesystems would not be included here.
* faults

Information about process control, such as trap and interrupt rate. The faults columns are as follows:
o in

Number of device interrupts per second observed in the interval. Additional information can be found in Assessing disk performance with the vmstat command.
o sy

The number of system calls per second observed in the interval. Resources are available to user processes through well-defined system calls. These calls instruct the kernel to perform operations for the calling process and exchange data between the kernel and the process. Because workloads and applications vary widely, and different calls perform different functions, it is impossible to define how many system calls per-second are too many. But typically, when the sy column raises over 10000 calls per second on a uniprocessor, further investigations is called for (on an SMP system the number is 10000 calls per second per processor). One reason could be “polling” subroutines like the select() subroutine. For this column, it is advisable to have a baseline measurement that gives a count for a normal sy value.
o cs

Number of context switches per second observed in the interval. The physical CPU resource is subdivided into logical time slices of 10 milliseconds each. Assuming a thread is scheduled for execution, it will run until its time slice expires, until it is preempted, or until it voluntarily gives up control of the CPU. When another thread is given control of the CPU, the context or working environment of the previous thread must be saved and the context of the current thread must be loaded. The operating system has a very efficient context switching procedure, so each switch is inexpensive in terms of resources. Any significant increase in context switches, such as when cs is a lot higher than the disk I/O and network packet rate, should be cause for further investigation.

Redirection on unix

Redirection on unix

Redirecting stdout and stderr
ls > file – redirect output to file
ls 2> filename – redirect error to file named filename
ls 2>&1 file – redirect error to where output is going to file named file
ls 1>&2 file – redirect stdout to stderr to file named file
ls > file 2> err – redirect output to file and error to file named err
exec 2> std.err – Redirect all error messages to file named std.err