#!/bin/ksh # # Script Name: topps_cumcpu_anyhost # Where: in $FEDIR/scripts where FEDIR=/apps/nns_com/fea # # Purpose: # Lists the top processes on ANY host in terms of the 'ps -ef' TIME column. # Uses the 'ps', 'cut', 'sed', 'paste', and 'sort' commands. # # Called by: feautils.menu/hostvu.menu script (or manually) # # Written by: B. Montandon 13Sep96 # Updated by: B. Montandon 28Oct96 added prompt for second image # Updated by: B. Montandon 23May97 used awk instead of cut to re-format # 'ps -ef' output; removed 'prelim version' note OUTLIST=$HOME/temp.lis . $FEDIR/scripts/clearnns echo "\ .......................................................................... ${HIbold}\ Show Processes on a host (one or two snapshots) (sorted by Accumulated-CPU, since last boot) This Host: `hostname` ${HIreset} Commands used: 'ps -ef' in a complex way (with 'awk' and 'sort') plus an optional second image at a user-specified time .......................................................................... ${HIdim} You will be given an opportunity to browse output in $OUTLIST in this window. .......................................................................... ${HIreset} NOTE: You can do this 'topps_cumcpu' display for this host and then use this nnsFEAmenu option again to start a 'topps_cumcpu' display for another host. The side-by-side comparision can be helpful to see, for example, possible related activity on a client and a server. -OR- You may want to start an 'osview' display for the same host -- to look for correlations between 'topps_cumcpu' processes and 'osview' activity. .......................................................................... ${HIbold} Enter HOSTNAME (default = this host, `hostname` ) ('x' to exit) ==>${HIreset} \c" read hostname1 if test "$hostname1" = "x" then continue # break fi HOSTNAME=$hostname1 LOCALHOST="N" if test \( "${hostname1}" = "" -o "${hostname1}" = "`hostname" \) then HOSTNAME=`hostname` LOCALHOST="Y" fi HOSTNAME3=`/usr/etc/arp $HOSTNAME` HOSTNAME2=`echo "$HOSTNAME3" |sed "s|-- no entry||"` # HEADRECS=10 # if test "$HOSTNAME" = "sgia" # then # HEADRECS=60 # fi # if test "$HOSTNAME" = "sgib" # then # HEADRECS=60 # fi echo "\ .............................................................................. Processes on this host: $HOSTNAME2 (one or two snapshots) (SORTED BY Accumulated CPU time, since last boot) Commands used: 'ps -ef' in a complex way (with 'awk' and 'sort') plus an optional second image at a user-specified time .............................................................................. The column headings and the meaning of the columns in a 'ps -ef' listing are given below. The usually-useful headings are described here. Others are described below the list of processes running now. TIME The cumulative execution time for the process. UID The login name of the process owner. PID The process ID of the process. PPID The process ID of the parent process. STIME The starting time of the process, given in hours (if any), minutes, and seconds. (A process begun more than twenty-four hours before the ps inquiry is executed is given in months and days.) COMD The the full command name and its arguments. ........................................................................... Top TIME Processes on Host $HOSTNAME: TIME UID PID PPID C STIME TTY COMD min:sec -------- ------- ----- ----- - -------- ------ --------------------------- " > $OUTLIST if test "$LOCALHOST" = "Y" then WORKDIR="/local/scratch" echo " .....................`date`.............................. " >> $OUTLIST ps -ef | nawk 'BEGIN { } NR == 1 {next} $5 ~ /..:..:../ { # print $7 " " $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $8 printf ("%8s %-8s %5s %5s %1s %8s %-8s %s \n", $7, $1, $2, $3, $4, $5, $6, $8) # print "" next } $5 !~ /..:..:../ { # print $8 " " $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $9 printf ("%8s %-8s %5s %5s %1s %3s %-4s %-8s %s \n", $8, $1, $2, $3, $4, $5, $6, $7, $9) # print "" next } ' | sort -t: +0nr -1 +1r -2 >> $OUTLIST echo " If you want a 2nd snapshot, enter 2 whenever you wish. Otherwise, press Enter to see one snapshot. (2/null) ==>${HIreset} \c" read ANOTHER if test "$ANOTHER" = "2" then echo " .....................`date`.............................. " >> $OUTLIST ps -ef | nawk 'BEGIN { } NR == 1 {next} $5 ~ /..:..:../ { # print $7 " " $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $8 printf ("%8s %-8s %5s %5s %1s %8s %-8s %s \n", $7, $1, $2, $3, $4, $5, $6, $8) # print "" next } $5 !~ /..:..:../ { # print $8 " " $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $9 printf ("%8s %-8s %5s %5s %1s %3s %-4s %-8s %s \n", $8, $1, $2, $3, $4, $5, $6, $7, $9) # print "" next } ' | sort -t: +0nr -1 +1r -2 >> $OUTLIST fi else . $FEDIR/scripts/mak_rhosts rsh $HOSTNAME $FEDIR/scripts/topps_cumcpu_rmt $OUTLIST # . $FEDIR/scripts/mv_rhosts fi echo " .............................................................................. Other column heading descriptions: TTY The controlling terminal for the process. (A question mark, ?, is printed when there is no controlling terminal). C Processor utilization for scheduling. A process that has exited and has a parent, but has not yet been waited for by the parent, is marked . ............................................................................. " >> $OUTLIST . $FEDIR/scripts/shofil $OUTLIST # END of script. Notes follow. # NOTES ON 'ps -ef' and 'ps -el' output attempts: # # First attempts: (Does not sort well on TIME, for some non-obvious reason?) # ps -ef | sort +6 -r | head >> $1 # ps -ef | sort +6 -r >> $1 # ## Output of 'ps -ef': ## ## Cols: ## 1-8 9-14 15-20 21-23 24-32 33-39 40-46 47- ## UID PID PPID C STIME TTY TIME COMD ## ## Examples: ## root 1 0 0 Sep 03 ? 0:04 /etc/init ## root 507 1 0 Sep 03 tablet 0:00 /sbin/getty ttyd1 co_9600 ## bmo01 3320 3297 0 08:16:38 pts/9 0:00 -ksh ## ## Importance to this list: ## UID PID PPID C STIME TTY TIME COMD ## ** * * * *** ** ## ## UID PID PPID STIME TIME COMD ## # ps -ef | cut -c1-8,9-14,15-20,24-29,31-32,40-46,47- | sort -r +4 | \ # head -$HEADRECS >> $1 # ## Output of 'ps -el': ## ## Cols: ##1-2 5-10 11-16 17-22 26-29 33-35 36-47 48-55 56-63 64-70 71- ## 3-4 23-25 30-32 ## F S UID PID PPID C PRI NI P SZ:RSS WCHAN TTY TIME COMD ## ## Examples: ##30 S 0 1 0 0 39 20 * 74:46 881b65b0 ? 0:04 init ##30 S 0 507 1 0 28 20 * 294:103 881b78d0 tablet 0:00 getty ##30 S 2250 3320 3297 0 28 20 * 348:116 881b6a30 pts/9 0:00 ksh ## ## Importance to this list: ## F S UID PID PPID C PRI NI P SZ:RSS WCHAN TTY TIME COMD ## ** ** * * *** ** ## ## UID PID PPID SZ:RSS TIME COMD ## # ps -el | cut -c5-10,11-16,17-22,36-47,64-70,71- | sort -r +4 | \ # head -$HEADRECS >> $1