#!/bin/ksh ## ## SCRIPT NAME: runcmd_on_pingable_hosts_bygui ## ## Where: in $FEDIR/scripts where FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: Generates a list of (SGI) hosts [preferably 'live' (ping-able)], ## and runs a specified Unix command or script on each host. ## ## Prepares the list of hosts from NIS ('ypcat hosts', i.e. ## from /etc/hosts on server). ## ## Could use DNS ('nslookup') in the future, ## if that provides a more complete list. ## But that will probably be much slower due to the ## large number of DNS entries in the nns.com domain. ############################################################################## ## INPUTS: Gets the command-string to run via a Tk GUI. ## ############################################################################## ## CALLED BY: A 'winterm -e' line in a toolchest definition ## for a toolchest script like 'nethosts_tools' ## in $FEDIR/scripts. ## ############################################################################## ## MAINTENANCE HISTORY: ## Written by: B. Montandon 6Apr2000 Based on 'rsh_w.ping' and ## 'sho_pingable_hosts' in $FEDIR/scripts ## and 'cleanbat_local_scratch_oldfils_allhosts' ## in /apps/ideas/cron. ## Updated by: B. Montandon 11Apr2000 Add RSH_RETCODE check. ## Updated by: B. Montandon 20Apr2000 Add 1st word of $CMD4HOSTS as a suffix ## to $OUTLIST name. ## Updated by: B. Montandon 5May2000 Fix $OUTLIST name to suuport fully- ## qualified command names (ditch CMD4HOSTS). ## Updated by: B. Montandon 25Sep2000 Chg method of getting HOSTLIST --- from ## 'ypcat hosts' to grep of a DNS-created ## list of SGI hosts, ## "$FEDIR/lists/hosts_SGI_via_DNS.lis". ## Updated by: B. Montandon 5sep2001 Add message to indicate output is going ## into $OUTLIST, and 'tail -f $OUTLIST' can ## be used to 'follow' the command output. ## Updated by: B. Montandon 12Mar2002 Set new variable HOSTS_FILE = ## "$FEDIR/lists/hosts_SGI_via_DNS.lis". ## Updated by: B. Montandon 13may2002 Put var $HOSTS_FILE in GUI msg, WIN_INFO. ## Updated by: B. Montandon 30apr2003 Add the name of the hosts file, ## $HOSTS_FILE to the report header. ## Updated by: B. Montandon 20oct2003 Add example of 'nethosts_tools' call in ## $HOME/.auxchestrc to report trailer. ## Updated by: B. Montandon 9jan2004 Put the name of the current report file, ## $OUTLIST, in several places: ## 1) bottom of GUI message area ## 2) bottom of execution-msgs window (was ## already at the top) ## 3) bottom of report file, $OUTLIST. ############################################################################## if test "$FEDIR" = "" then FEDIR="/apps/nns_com/fea" fi HOSTS_FILE="$FEDIR/lists/hosts_SGI_via_DNS.lis" ## FOR TESTING (with just a few hosts): # HOSTS_FILE="$FEDIR/lists/hosts_SGI_via_DNS.lis_TESTfewhosts" ############################################################################## ## GENERATE THE NAME OF THE OUTPUT-REPORT FILE. ############################################################################## . $FEDIR/scripts/set_localoutlist ## SUFFIX=`echo "$CMD4HOSTS" | cut -d" " -f1 | sed 's|/|_|g'` TIMESTAMP=`date +%Y%b%d_%T%p` OUTLIST=${OUTLIST}_runcmd_pingable_hosts_${TIMESTAMP} rm -f $OUTLIST ############################################################################## ## GET THE NAME OF THE COMMAND/SCRIPT TO RUN. ############################################################################## WIN_TITLE="RunCmd_onAllHosts, from `hostname`, by $USER" export WIN_TITLE ## OLD METHOD OF GETTING HOSTNAMES: ## The command/script will be run on all 'iaw' hosts given by NIS (yellow pages), ## i.e. on 'iaw' hosts given by the 'ypcat hosts' command. WIN_INFO="\ Enter the name of a Unix command or the fully-qualified name of a script. The command/script will be run on all SGI hosts given by a hostnames list in $HOSTS_FILE See that file for info on how that file is updated. Example commands: lpstat -t To check on 'lp' queues on each host. lpstat -a To check on 'lp' queues on each host (shorter form). /usr/etc/lpc status To check on 'lpr' queues on each host. last To see recent users of each host. uname -a To check operating system release level on each host. uname -aRp To check OS release level, incl. mod level, on each host. ls -l /etc/sendmail.cf To see permissions/modify-date/size of a file on each host. ls -l /local/apps To see locally installed apps, if any, on each host. du -ksl /local/scratch To see space occupied by files under /local/scratch. /etc/sysinfo -s To see host identifier (for license control) on each host. /usr/etc/netstat -i To see packet errs/collisions for network interfaces on each host. /usr/etc/netstat -in To see IP address and errs/collisions on each host. sar -c 2 1 To see syscalls (reads,writes,chars/sec) on each host. ps -ef | grep xxx | grep -v grep To see 'xxx' processes on each host. Example: xxx = orbixd Can also run script with a combination of cmds like awk,sort where an awk program reformats and/or selects output lines. Example: $FEDIR/scripts/runcmd_topps_cumcpu_1host To see top Cum-CPU processes on each host. $FEDIR/scripts/mk_lpr_spooldirs_1host To make 'lpr' 'spool' directories on each host. $FEDIR/scripts/remov_locapps_ideas6_1host To remove local install of some of I-DEAS 6 on each host. BEFORE USING THIS UTILITY, which runs the command on MANY hosts, THOROUGHLY TEST 'UPDATE' SCRIPTS, LIKE FILE REMOVAL, ON SINGLE HOST(S). If the command runs quickly, the entire set of hosts will be traversed within a minute or two. ---------------------------------------------------------------------------- Output from the command/commands-pipe, run on the hosts, will be put in file $OUTLIST ---------------------------------------------------------------------------- This script is $0 It is using hostnames from manually-updated file $HOSTS_FILE " export WIN_INFO WIN_PROMPT="Command:" export WIN_PROMPT ## Optional initialization of entry with a default: WIN_ENTRY="lpstat -t" export WIN_ENTRY ## Optional setting of color scheme for the window: WIN_COLOR="lightskyblue" export WIN_COLOR ## FOR TESTING: # set -x CMD4HOSTS=`$FEDIR/tkGUIs/enter_at1prompt.tk` ## FOR TESTING: # set - if test "$CMD4HOSTS" = "" then exit fi ############################################################################## ## GENERATE THE HOSTLIST. ## 1) Originally from NIS (ypcat hosts | grep ...). ## ## 2) After DNS implemented, by an occasionally updated file of hostnames. ## [This is not ideal. But even real-time DNS queries do not show all ## of the still-used workstations, if they are not booted up.] ############################################################################## ## . $FEDIR/scripts/alarm_sethostlist ## . /apps/ideas/cron/set_hostlist ## DEACTIVATED 25sep2000. 'ypcat hosts' no longer gives SGI-'iaw' host names. # HOSTLIST=`ypcat hosts | grep -v "^#" | grep iaw | awk '{print $3}' | sort` HOSTLIST=`grep -v "^#" $HOSTS_FILE` ## FOR TESTING: # HOSTLIST="iaw005 iaw007 iaw021 iaw030 iaw141" ############################################################################# ## PREPARE A HEADER FOR THE REPORT. ############################################################################# echo "\ ****************************** `date '+%Y %b %d %a %T%p'` ***************** OUTPUT FROM THE COMMAND: $CMD4HOSTS which is run on site SGI hosts --- by userid $USER with the candidate hostnames provided via file $HOSTS_FILE : " > $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 -- TO EXECUTE THE "$CMD4HOSTS". ############################################################################## ## CATCH THE OUTPUT FROM A SINGLE PING WITH A SMALL 4-BYTE PACKET. ############################################################################## echo "\ **************************************************************************** Each host in $HOSTS_FILE will be pinged to check availability. The command ' $CMD4HOSTS ' will be executed on available hosts. Standard output will be put in $OUTLIST . You can 'follow' the output by using the command tail -f $OUTLIST in another window. **************************************************************************** " for HOST in $HOSTLIST do echo "\nPinging $HOST to check availability." ## FOR TESTING: # set -x ########################################################################### ## PING THE HOST BEFORE TRYING 'rsh' --- and CATCH THE OUTPUT ## FROM A SINGLE PING WITH A SMALL 4-BYTE PACKET --- to use to ## determine whether to do 'rsh' on the host. ########################################################################### PINGOUT=`/usr/etc/ping -s 4 -c 1 $HOST` ## FOR TESTING: # echo "$PINGOUT # # " ## FOR TESTING: # set - PINGCHECK=`echo $PINGOUT | grep '100.0% packet loss'` if test "$PINGCHECK" = "" then echo " --------------------------------------------------------------------- OUTPUT OF COMMAND ON $HOST:\n" >> $OUTLIST ## FOR TESTING: # set -x rsh $HOST "$CMD4HOSTS" >> $OUTLIST RSH_RETCODE=$? if test $RSH_RETCODE = 1 then echo "COMMAND WAS NOT RUN ON $HOST. IT APPEARS THAT 'rsh' FAILED FOR USERID $USER.\n" >> $OUTLIST fi else echo " --------------------------------------------------------------------- NO OUTPUT from $HOST. NOT PING-ABLE." >> $OUTLIST fi done ######################################################################## ## Add a message, in the execution messages window, to tell where ## the report file is located. ######################################################################## echo " Output from the command/commands-pipe, run on the hosts, will be put in file $OUTLIST" ######################################################################## ## Add TRAILER to report. ######################################################################## THIS_SCRIPT_BASENAME=`basename $0` echo " ****************************** `date '+%Y %b %d %a %T%p'` ******************* The command $CMD4HOSTS was executed on 'recently ping-able hosts', as listed above and as seen in file $HOSTS_FILE. The command-GUI was presented by and the command was run by the script $0 ----------------------- Output, from the command run on the hosts, was put in this report file, named: $OUTLIST ----------------------- IMPLEMENTATION METHODS: The '$THIS_SCRIPT_BASENAME' script can be implemented 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'. Typically, an site SGI application administrator coul add the 'nethosts_tools' toolchest to his/her SGI toolchest via their .auxchestrc file. Example line in \$HOME/.auxchestrc : \"NetHosts_Tools\" f.checkexec.sh \"/apps/nns_com/fea/scripts/nethosts_tools\" ........................................................................... " >> $OUTLIST ##################################################################### ## SHOW THE REPORT. ##################################################################### ## 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 & ## DOES NOT SHOW UP in an 'xwsh'. $FEDIR/tkGUIs/shofil.tk