#! /bin/ksh ## ## SCRIPT NAME: runcmd_topps_cumcpu_1host ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################ ## PURPOSE: To show the top processes on a host --- in terms of Cumulative ## CPU time --- based on a CPUMIN threshold variable, which is ## hardcoded to a value, like 5 min. ## ## This script puts all (report, text) output to STDOUT. ## ## The script is intended to be called from the ## 'runcmd_on_pingable_hosts_bygui' utility ## which may be called from 'nethosts_tools'. ## ############################################################################ ## CALLED BY: nethosts_tools -> runcmd_on_pingable_hosts_bygui ## in $FEDIR/scripts ## ############################################################################ ## CALL FORMAT: ## The full command name /apps/nns_com/fea/scripts/alarm_top_ps_1host ## can be entered in the 'Command:' entry field in the ## 'runcmd_on_pingable_hosts_bygui' GUI. ## ############################################################################ ## INPUT VARS: $1 could contain a value for the CPUMIN threshold variable. ## ############################################################################ ## MAINTENANCE HISTORY: ## Written by: B.Montandon O06 10Apr2000 Based on 'alarm_top_ps_1host' ## Updated by: B.Montandon O06 10Apr2000 ## ############################################################################ ############################################################################ ## Set the CPUMIN threshold variable. ############################################################################ # CPUMIN=2 # CPUMIN=120 CPUMIN=5 if test ! "$1" = "" then CPUMIN=$1 fi ############################################################################ ## Prepare message heading for the host on which this script is run. ############################################################################ HOSTNAME=`hostname` ########################################## ## Get IP address of host. ## (better way? with 'netstat -in'? 'ifconfig'?) ########################################## HOSTNAME_ARP=`/usr/etc/arp $HOSTNAME` HOSTNAME2=`echo "$HOSTNAME_ARP" |sed "s|-- no entry||"` BOOTTIME=`who -b` # DATETIME=`date` DATETIME=`date '+%Y %b %d %T%p'` echo "\ HOST: $HOSTNAME2 **** $DATETIME ****************** HOST PROCESSES (other than X-server 'Xsgi') THAT HAVE ACCUMULATED ** MORE THAN $CPUMIN MINUTES OF CPU-TIME ** since their start. $BOOTTIME 'ps -ef' records, i.e. processes -- sorted by CUM-CPU-time -- and > $CPUMIN mins. 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. ################################################################################# ## Handle either format of 'ps -ef' output (date or time started): ## root 408 393 0 Mar 13 ? 1:17 /usr/etc/lpd ## bmo01 84332 86747 0 08:33:49 ? 7:00 netscape -mail ################################################################################# # 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` ############################################################################ ## If CPU-mins > $CPUMIN and process is not Xsgi, output those process-info ## 'exception' lines to STDOUT. ############################################################################ echo "$WINMSG0" | awk -v CPUMIN=$CPUMIN -F: 'BEGIN {print ""} (( $1 > CPUMIN ) && ( $0 !~ /Xsgi/ )) {print $0} ' ##################################################### ### If CPU-min threshold were not available in a var, ### CPU-min could be HARDCODED. Example: ##################################################### ## echo "$WINMSG0" | awk -F: 'BEGIN {print ""} ## (( $1 > 2 ) && ( $0 !~ /Xsgi/ )) {print $0} ' #####################################################