#!/bin/ksh ## ## SCRIPT NAME: sho_pingable_hosts ## ## Where: in $FEDIR/scripts where FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: From a list of (NNS SGI) hosts --- hostnames contain 'iaw' string ## --- pings each one and constructs a list of the 'live' (ping-able) ## ones. ## ## Prepares the list of hosts from either ## ## - NIS ('ypcat hosts', i.e. /etc/hosts on server) ## or ## - DNS ('nslookup'). See code below for the current method. ## ## ----------------------------------------------------------------- ## ## Utlimate Purpose: ## If admin utilities are run on a host list and some hosts are ## 'off-line', the 'rsh' admin command/script will hang for about ## twenty to 30 seconds at each 'off-line' host. ## ## The list generated here provides a semi-automatic means of ## checking the basis for generating a list of 'live' ## workstations --- for Application/System Admin tasks ## --- such as, looking for clients needing printer ## cleanup or definitions. Another example: looking for ## hosts with full file-systems or hosts with 'run-away' ## processes. ############################################################################## ## INPUTS: none ## ############################################################################## ## CALLED BY: A 'winterm -e' line in a toolchest definition ## for a toolchest script like 'nethosts_tools' ## in $FEDIR/scripts ## OR ## hosts_on_sgia.menu in $FEDIR/scripts, which is called via ## feamain -> feautils.menu -> hostvu.menu -> hosts_on_sgia.menu ## or feamain -> feautils.menu -> netvu.menu -> hosts_on_sgia.menu ## or feamain -> feahelpg.menu -> hosts_on_sgia.menu ## ############################################################################## ## MAINTENANCE HISTORY: ## Written by: B. Montandon 6Apr2000 Based 'rsh_w.ping' ## in $FEDIR/scripts ## and 'cleanbat_local_scratch_oldfils_allhosts' ## in /apps/ideas/cron ## Other references: 'alarm_sethostlist' and ## 'alarm_scan' in $FEDIR/scripts. ## Updated by: B. Montandon 5May2000 Add message to stdout that a summary ## report will be shown. ## Updated by: B. Montandon 25Sep2000 Chg method of getting HOSTLIST --- from ## 'ypcat hosts' to grep of a DNS-created ## list of SGI hosts. ############################################################################## if test "$FEDIR" = "" then FEDIR="/apps/nns_com/fea" fi ############################################################################## ## GENERATE THE NAME OF THE OUTPUT-REPORT FILE. ############################################################################## . $FEDIR/scripts/set_localoutlist OUTLIST2=${OUTLIST}2 # rm -f $OUTLIST # rm -f $OUTLIST2 ################################################################ ## GENERATE THE $HOSTLIST ENV-VAR. ################################################################ ############################################################ #### 'alarm_sethostlist' is used in #### /apps/nns_com/fea/scripts/alarm_scan ############################################################ ## . $FEDIR/scripts/alarm_sethostlist ############################################################ ############################################################ #### 'set_hostlist' is used in ####/apps/ideas/cron/cleanbat_local_scratch_oldfils_allhosts ############################################################ ## CRONDIR="/apps/ideas/cron" ## . $CRONDIR/set_hostlist ############################################################ ######################################################### ## DEACTIVATED 25sep2000. ## 'ypcat hosts' no longer gives SGI-'iaw' host names. ######################################################### # HOSTLIST=`ypcat hosts | grep -v "^#" | egrep 'iaw' | \ # awk '{print $3}' | sort` # # HOST_SOURCE_DESC="NIS (the 'ypcat hosts' command)" ######################################################## HOSTLIST=`grep -v "^#" $FEDIR/lists/hosts_SGI_via_DNS.lis` HOST_SOURCE_DESC="DNS (a periodically generated list of SGI hosts, in $FEDIR/lists/hosts_SGI_via_DNS.lis)" ## FOR TESTING: # HOSTLIST="iaw030 iaw005 iaw007 iaw021" ############################################################################# ## PREPARE A HEADER FOR THE REPORT. ############################################################################# echo "\ ******************************** `date '+%Y %b %d %T%p'` ********************* CURRENTLY PING-ABLE HOSTS among 'iaw' hosts with candidate hostnames provided via $HOST_SOURCE_DESC : " > $OUTLIST ############################################################################## ## IF WE WERE GOING TO EXECUTE A COMMAND/SCRIPT ON EACH HOST, ## WE COULD ASSURE THE USER HAD A .rhosts FILE. ############################################################################## # echo "+ $USER" > $HOME/.rhosts # . $FEDIR/scripts/mak_rhosts ############################################################################## ## LOOP THRU HOSTS. ############################################################################## ## CATCH THE OUTPUT FROM A SINGLE PING WITH A SMALL 4-BYTE PACKET. ############################################################################## echo "\ A report summarizing the ping-able hosts will appear at the end of this sequence of pinging all hosts. Generally, where there is a pause of about 10 seconds in the following 'Pinging' messages, the host is not pingable. [You can break out using Alt-Break, with cursor in this window.] " CNTHOSTS=0 CNTNOPINGS=0 CNTNORESOLV=0 CNTPINGS=0 for HOST in $HOSTLIST do echo "Pinging $HOST" ## FOR TESTING: # set -x PINGOUT=`/usr/etc/ping -s 4 -c 1 $HOST 2>&1` ## FOR TESTING: # echo "$PINGOUT # # " CNTHOSTS=`expr $CNTHOSTS + 1` ## FOR TESTING: # set - PING_100LOSS=`echo $PINGOUT | grep '100.0% packet loss'` PING_RESOLVE=`echo $PINGOUT | grep 'Cannot resolve'` if test ! "$PING_100LOSS" = "" then ## FOR TESTING: # echo "$HOST NOT PING-ABLE. $PINGOUT" >> $OUTLIST echo "$HOST 100% NOT PING-ABLE" >> $OUTLIST CNTNOPINGS=`expr $CNTNOPINGS + 1` elif test ! "$PING_RESOLVE" = "" then ## FOR TESTING: # echo "$HOST NOT RESOLVABLE. $PINGOUT" >> $OUTLIST echo "$HOST NOT RESOLVABLE" >> $OUTLIST CNTNORESOLV=`expr $CNTNORESOLV + 1` else ## FOR TESTING: # echo "$HOST. $PINGOUT" >> $OUTLIST echo "$HOST" >> $OUTLIST CNTPINGS=`expr $CNTPINGS + 1` fi done ######################################################################## ## Add TRAILER to report. ######################################################################## echo " ******************************** `date '+%Y %b %d %T%p'` ********************* The list of currently ping-able hosts, above, was generated by the script $0 Number of Hosts pinged: $CNTHOSTS Unresolved hosts: $CNTNORESOLV 100% packet-loss hosts: $CNTNOPINGS Ping-able hosts: $CNTPINGS Unless the host was marked '100% NOT PING-ABLE' or 'NOT RESOLVABLE' in the list above, the host is assumed to be pinged successfully. Such a list is helpful to SGI System & Application Administrators who need to scan hosts for various kinds of maintenance tasks, for example, - providing new print queue definitions - removing old print queue definitions - checking for full file-systems - checking for 'run-away' processes - checking host configuration files/parameters - checking locally-installed application files/parameters etc. The list also can be used to indicate workstation names that are no longer in use and perhaps should be removed from some OS or Administrator host lists. -------- IMPLEMENTATION METHODS: You can implement the script as - a command alias, via your .profile file; - a desktop icon, via the 'Find, File QuickFind' tool drawers; - a drawer in the SGI toolchest, via your .auxchestrc file. Or the script could be accessed via a drawer in a command toolchest-utility, like 'nethosts_tools'. This report can be also generated via nnsFEAmenu option 'u n ?' (Utilities, Net-vu, ?). ........................................................................... " >> $OUTLIST ##################################################################### ## SHOW THE REPORT --- list of ping-able hosts. ##################################################################### ## FOR TESTING: # echo " # DISPLAY: $DISPLAY" # # set -x ##################################################################### ## $FEDIR/scripts/shofil Does not work in an 'xwsh' from toolchest. ## Apparently, ## because of '&' batch invocation of shofil.tk within this script. ##################################################################### # $FEDIR/scripts/shofil $OUTLIST ##################################################################### SHOFILENAME=$OUTLIST export SHOFILENAME XLPHP_FORMAT="AV" export XLPHP_FORMAT $FEDIR/tkGUIs/shofil.tk