#!/bin/csh -f # # usage: # # makep executable nproc machine1 [machine2 ...] # # or # # makep executable nproc name_of_file_containing_machine_list # # e.g. # makep /nfs/home/qmd 3 sun1 sun2 ibm dec next cray > qmd.p # makep /nfs/home/qmd 3 machlist > qmd.p # # makep queries each of the machines in the list and assembles # a list of those alive, ordered by load. A TCGMSG procgrp file # is then written to standard output for up to nproc processes. # # If at least nproc accessible machines are found makep returns status 0, # otherwise non-zero. # # It is assumed that # 1) a temporary file in /tmp may be used # 2) the current user name name has rlogin rights to all machines # 3) that /tmp should be the work directory for all machines # 4) that the executable path is the same on all machines # # Adapted from a script by Michael B. Coolidge, coolidge@gauss.usafa.af.mil # # # deconvolute the argument list and make the list of machines # if ($#argv < 3) then echo $#argv echo Too few arguments goto usage endif set executable = "$1" set nproc = "$2" shift argv shift argv if ($#argv == 1 && -e "$1") then set machines = (`cat "$1"`) else set machines = ($argv[*]) endif # figure out who is awake and get their load /bin/rm -f /tmp/makep.tmp2.$$ foreach node ($machines[*]) IF IBM IBMNOEXT /etc/ping -c 3 $node >& /dev/null ELSE /usr/etc/ping $node >& /dev/null ENDIF if ($status == 0) then getinfo: rsh $node -n uptime >& /tmp/makep.tmp1.$$ # ruptime $node >& /tmp/makep.tmp1.$$ if ($status == 0) then set info = (`cat /tmp/makep.tmp1.$$`) if ("$info" == "") then echo '#' ${node}: $info goto getinfo endif # average: from ucb version of uptime # processes: from IBM AIX version (also counts current process) echo '#' ${node}: $info while ("$info[1]" != "load:" && "$info[1]" != "average:" && "$info[1]" != "processes:") shift info end set load = $info[2] if ("$info[1]" == "processes:") @ load -- echo $load $node >> /tmp/makep.tmp2.$$ /bin/rm -f /tmp/makep.tmp1.$$ endif /bin/rm -f /tmp/makep.tmp1.$$ else echo '#' $node is down endif end # sort the list of machines by load and write the procgrp set machines = (`sed 's/,//g' /tmp/makep.tmp2.$$ | sort -n`) @ nmach = $#machines / 2 /bin/rm -f /tmp/makep.tmp2.$$ if ($?USER == 0) setenv USER `whoami` while ($nproc != 0 && $nmach != 0) @ nproc -- @ nmach -- echo \# $machines[2] load = $machines[1] # Used to use /tmp directory echo $USER $machines[2] 1 $executable `pwd` if ($nmach != 0) then shift machines shift machines endif end exit $nproc