#! /bin/ksh ## ## SCRIPT NAME: alarm_top_ps_1host ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################ ## PURPOSE: To show NNS menu of network-scanning utilities that pop a window ## (process) from each host exhibiting an 'exception' condition. ## ############################################################################ ## CALLED BY: feamain -> feautils.menu -> netscan.menu -> ## netalarm.menu -> alarm_scan --- or manually ## ############################################################################ ## CALL FORMAT: ## . $FEDIR/scripts/alarm_scan $FEDIR/scripts/alarm_top_ps_1host ## within which ## ( rsh $hostid $1 $THISHOST ) & ## is executed, where $1 represents the script name -- in this case ## 'alarm_top_ps_1host' ############################################################################ ## INPUT VARS: $1 contains name of host on which to 'pop' the window alarm-msg ## ############################################################################ ## MAINTENANCE HISTORY: ## Written by: B.Montandon C61 5May97 ## Updated by: B.Montandon O06 17Mar99 Added the CPUMIN var, in place of ## 2 min hardcoded. ############################################################################ ############################################################################ ## Set DISPLAY location for the following xwsh-winmsg display. ############################################################################ if test ! "$1" = "" then DISPLAY=${1}:0 export DISPLAY fi ############################################################################ ## Set a work file (& list file, unused at this time). ## Using in-memory variables WINMSG,WINMSG2 instead of the work file. ############################################################################ # if test -w /local/scratch # then # OUTWORK=/local/scratch/topcpu_temp.all # # OUTLIST=/local/scratch/topcpu_temp.lis # else # OUTWORK=$HOME/topcpu_temp.all # # OUTLIST=$HOME/topcpu_temp.lis # fi ############################################################################ ## Prepare alarm message heading. ############################################################################ # CPUMIN=2 # CPUMIN=120 CPUMIN=5 HOSTNAME=`hostname` ## Get IP address of host. (better way? with 'netstat -in'? 'ifconfig'?) HOSTNAME3=`/usr/etc/arp $HOSTNAME` HOSTNAME2=`echo "$HOSTNAME3" |sed "s|-- no entry||"` BOOTTIME=`who -b` DATETIME=`date` WINMSG=`echo "\ **************** $DATETIME ****************** SGI WORKSTATION non-Xsgi-PROCESSES THAT HAVE ACCUMULATED ** MORE THAN $CPUMIN MINUTES OF CPU-TIME ** since their start $BOOTTIME *** HOST: $HOSTNAME2 *** < ps -ef > records, i.e. processes -- sorted by most CUM-CPU-time. CUM-CPU Parent Start TIME User Procss Procss TIME COMMAND min:sec ID ID ID /Date -------- ----- ----- ----- -------- ---------------------- "` ################################################################################# ## Reformat the ps -ef output so that CPU-time is in 1st col; and sort by CPU-time. ## Put this in an environment variable, WINMSG0. Could use a work file if necessary. ################################################################################# # set -x # ps -ef | nawk 'BEGIN { WINMSG0=`ps -ef | nawk 'BEGIN { } NR == 1 {next} $5 ~ /..:..:../ { # print $7 " " $1 " " $2 " " $3 " " $5 " " $8 printf ("%8s %8s %5s %5s %8s %s", $7, $1, $2, $3, $5, $8) print "" next } $5 !~ /..:..:../ { # print $8 " " $1 " " $2 " " $3 " " $5 " " $6 " "$9 printf ("%8s %8s %5s %5s %3s %-4s %s", $8, $1, $2, $3, $5, $6, $9) print "" next } ' | sort -t: +0nr -1 +1r -2` # ' | sort -t: +0nr -1 +1r -2 > $OUTWORK ############################################################################ ## If CPU-mins > $CPUMIN and process is not Xsgi, output those process-info ## 'exception' lines to var WINMSG2. ############################################################################ # WINMSG2=`cat $OUTWORK | awk -F: 'BEGIN {print ""} WINMSG2=`echo "$WINMSG0" | awk -v CPUMIN=$CPUMIN -F: 'BEGIN {print ""} (( $1 > CPUMIN ) && ( $0 !~ /Xsgi/ )) {print $0} ' ` ### Before CPU-min was chgd to a var, CPU-min WAS HARDCODED: ## WINMSG2=`echo "$WINMSG0" | awk -F: 'BEGIN {print ""} ## (( $1 > 2 ) && ( $0 !~ /Xsgi/ )) {print $0} ' ` ############################################################################ ## If no 'exception' lines, could load WINMSG2 with a 'none' message. ############################################################################ # if test "$WINMSG2" = "" # then # WINMSG2=" # # ** NONE **" # fi ############################################################################ ## Display the alarm-msg in a window (sent to DISPLAY as set above), if ## $WINMSG2 is not empty. ############################################################################ if test ! "$WINMSG2" = "" then ############################################################################ ## If CPU-mins > $ and process is not Xsgi, add that process-info ## to the heading info. ############################################################################ WINMSG=$WINMSG$WINMSG2 export WINMSG ############################################################################ ## Display the alarm msg in an appropriately sized (& offset-by-secs) window. ############################################################################ MSGLINES=`echo "$WINMSG" | wc -l` MSGLINES=`expr $MSGLINES + 5` ROWLOC=`date +%S` ROWLOC=`expr 10 \* $ROWLOC` # set -x # xwsh -bg gray78 -fg black -hold -autofork \ xwsh -bg red2 -fg snow1 -autofork \ -title "TOPCPU_$HOSTNAME" -name "TOPCPU_$HOSTNAME" \ -fn -*-screen-medium-r-normal--15-*-*-*-m-80-iso8859-1 \ -geometry 80x${MSGLINES}+090+${ROWLOC} -e /apps/nns_com/fea/scripts/winmsg fi # set -