#! /bin/tcsh -f # {{{ Versioning and license info # # $Id: setup,v 1.13 2006/08/21 15:55:14 proclus Exp $ # Many thanks to Robert L. Campbell # Copyright (C) 2006 Michael L. Love # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # or find it at: http://www.gnu.org/copyleft/gpl.html # # }}} # {{{ Variable definitions setenv BOLD "" setenv UNBOLD "" setenv PREMARK "[01;" setenv POSTMARK "m" setenv UNMARK "" # cleanup ansi here ;-} # setenv UNMARK "" setenv UNMARK "" setenv UNMARK "" setenv UNMARK "" setenv LTGREY ${PREMARK}0${POSTMARK} setenv UNLTGREY ${UNMARK} setenv UNDERLINE ${PREMARK}4${POSTMARK} setenv UNUNDERLINE ${UNMARK} setenv BLINK ${PREMARK}5${POSTMARK} setenv UNBLINK ${UNMARK} setenv BLOCK ${PREMARK}7${POSTMARK} setenv UNBLOCK ${UNMARK} setenv GREY ${PREMARK}30${POSTMARK} setenv UNGREY ${UNMARK} setenv YELLOW ${PREMARK}33${POSTMARK} setenv UNYELLOW ${UNMARK} setenv GREEN ${PREMARK}32${POSTMARK} setenv UNGREEN ${UNMARK} setenv BLUE ${PREMARK}34${POSTMARK} setenv UNBLUE ${UNMARK} setenv CYAN ${PREMARK}36${POSTMARK} setenv UNCYAN ${UNMARK} setenv RED ${PREMARK}31${POSTMARK} setenv UNRED ${UNMARK} setenv MAGENTA ${PREMARK}35${POSTMARK} setenv UNMAGENTA ${UNMARK} setenv WHITE ${PREMARK}37${POSTMARK} setenv UNWHITE ${UNMARK} setenv BLOCKYELLOW ${PREMARK}43${POSTMARK} setenv UNBLOCKYELLOW ${UNMARK} setenv BLOCKGREEN ${PREMARK}42${POSTMARK} setenv UNBLOCKGREEN ${UNMARK} setenv BLOCKBLUE ${PREMARK}44${POSTMARK} setenv UNBLOCKBLUE ${UNMARK} setenv BLOCKCYAN ${PREMARK}46${POSTMARK} setenv UNBLOCKCYAN ${UNMARK} setenv BLOCKRED ${PREMARK}41${POSTMARK} setenv UNBLOCKRED ${UNMARK} setenv BLOCKMAGENTA ${PREMARK}45${POSTMARK} setenv UNBLOCKMAGENTA ${UNMARK} setenv BLOCKWHITE ${PREMARK}47${POSTMARK} setenv UNBLOCKWHITE ${UNMARK} # }}} # {{{ Set some basic/general values # determine operating system (architecture) setenv OS `uname -s` setenv OS_VERSION `uname -r` setenv MACHINE `uname -m` if ( -f /etc/debian_version ) then setenv DISTRO Debian else if ( -f /etc/fedora-release ) then setenv DISTRO FedoraCore else setenv DISTRO endif # make some big programs run better! if ( ${OS} != 'Darwin' && ${OS_VERSION} != '7.0.0' ) then unlimit stacksize limit coredumpsize 0 endif # }}} setenv pathDepth `echo $0 | sed s/'^\.'// | sed s/'^\/'// | sed s/'\/'/'\t'/g | wc -w` setenv progName `echo $0 | sed s/'^\.'// | sed s/'^\/'// | sed s/'\/'/'\t'/g | cut -f${pathDepth}` echo echo Welcome to ${GREEN}${progName}${UNGREEN} echo echo "Your OS is: ${CYAN}${DISTRO}${UNCYAN} " echo " ${BLUE}${OS}${UNBLUE} " echo " ${MAGENTA}${OS_VERSION}${UNMAGENTA} " echo " ${RED}${MACHINE}${UNRED} " echo setenv userName `grep :0:0: /etc/passwd |grep Love |cut -f1 -d:` # Most of these tests write a couple of bytes to /tmp/who_awake.tmp. # If you don't like that then you can disable some of the tests here # or run the the script with ssh option only, where ssh -q succeeds. setenv doNames yes setenv doSSH yes setenv doNFS yes setenv doUser yes setenv doLoad yes setenv doWeb yes setenv doDNS yes setenv doNode yes # doTest fails on purpose. setenv doTest no setenv divider ${BLUE}'|'${UNBLUE} # Clock ticker time in seconds, in order to give the network a rest setenv sleepTime 150 # Initialize ticker and command list. No need to change this. set doClock = 0 setenv theCommands `grep -a -H ':$' ${0} | cut -f2 -d:` while(1) # Machine name lists are set in the loop for on the fly changes. setenv theGNUs ' '`mydebip`' '`myworkip`' '`myjediip`' '`mysmasterip` setenv theSGIs `mysgiip` setenv theNodes `mysnode` setenv MASTER `mysmaster` if ( $progName == 'help' || $1 == 'help' ) then goto commands else if ( $#argv != 0 ) then goto $1 else setenv theGoto `grep -a -H ':$' ${0} | cut -f2 -d: | grep $progName` if ( ${theGoto} != '' ) then goto ${theGoto} endif endif # An up test based on ssh ssh: if ( ${doSSH} == 'yes' ) then echo -n "ssh "${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh -q ${userName}@${i} hostname > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${YELLOW}`cat /tmp/who_awake.tmp | cut -b 1,2`${UNYELLOW} else echo -n ${RED}`echo ${i} | cut -b1,2`${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'ssh' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto ssh else if ( ${progName} == 'ssh' ) then goto ssh endif # Print the name list name: if ( ${doNames} == 'yes' && ${1} != 'node' ) then echo -n "name"${divider} foreach i ( ${theGNUs} ) ( ssh -q ${userName}@${i} "netstat -r | grep default | tr -s ' ' | tr ' ' '\t' | cut -f8 | sed s/^/'ifconfig '/ | csh | grep 'inet addr:' | tr -s ' ' | tr ' ' '\t' | cut -f3 | sed s/addr:// | sed s/^/'host '/ | csh | head -1 | tr ' ' '\t' | cut -f5 | cut -f2 -d'(' | cut -b1,2" > /tmp/who_awake.tmp ) > & /dev/null grep '..' /tmp/who_awake.tmp > /dev/null if ( ${?} == 0 ) then echo -n ${YELLOW}`cat /tmp/who_awake.tmp`${UNYELLOW} else echo -n ${RED}'dn'${UNRED} endif echo -n ${divider} end foreach i ( ${theSGIs} ) ( ssh -q ${userName}@${i} "netstat -r | grep default | tr -s ' ' | tr ' ' '\t' | cut -f6 | sed s/^/'ifconfig '/ | csh | grep inet | tr -s ' ' | tr ' ' '\t' | cut -f3 | sed s/addr:// | sed s/^/'host '/ | csh | head -1 | tr ' ' '\t' | cut -f5 | cut -f2 -d'(' | cut -b1,2" > /tmp/who_awake.tmp ) > & /dev/null grep '..' /tmp/who_awake.tmp > /dev/null if ( ${?} == 0 ) then echo -n ${YELLOW}`cat /tmp/who_awake.tmp`${UNYELLOW} else echo -n ${RED}'dn'${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'name' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto name else if ( ${progName} == 'name' ) then goto name endif # An up test based on nfs access nfs: if ( ${doNFS} == 'yes' ) then echo -n "nfs "${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh ${userName}@${i} cat /nfs/fs/prog/up > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp`${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'nfs' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto nfs else if ( ${progName} == 'nfs' ) then goto nfs endif # Get the number of users on each machine from the uptime output. user: if ( ${doUser} == 'yes' ) then echo -n "user"${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh ${userName}@${i} 'uptime | cut -d, -f3 | cut -b2,3' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN} awk '{printf("%2i",$1)}' /tmp/who_awake.tmp echo -n ${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'user' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto user else if ( ${progName} == 'user' ) then goto user endif # Get the load on each machine from the uptime output. load: if ( ${doLoad} == 'yes' ) then echo -n "load"${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh ${userName}@${i} 'uptime | cut -f4 -d, | cut -f2 -d: | cut -b2,4 ' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp`${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'load' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto load else if ( ${progName} == 'load' ) then goto load endif if ( ${doWeb} == 'yes' ) then # An up test based on web access web: echo -n "web "${divider} foreach i ( ${theGNUs} ) ( ssh -q ${userName}@$i 'echo -n `lynx -source http://biophysics.med.jhmi.edu/up`' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp | cut -b1`${UNGREEN} else echo -n ${RED}d${UNRED} endif ( ssh -q ${userName}@$i 'echo -n `lynx -source http://proclus.gnu-darwin.org/up`' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp | cut -b2`${UNGREEN} else echo -n ${RED}n${UNRED} endif echo -n ${divider} end foreach i ( ${theSGIs} ) ssh -q ${userName}@$i 'echo -n `/usr/freeware/bin/lynx -source http://proclus.gnu-darwin.org/up` > /dev/null' if ( ${?} == 0 ) then echo -n ${GREEN}up${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'web' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto web else if ( ${progName} == 'web' ) then goto web endif dns: # Test access to name servers with ping on each machine. if ( ${doDNS} == 'yes' ) then echo -n "dns "${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh ${userName}@${i} 'echo -n `grep nameserver /etc/resolv.conf|head -1| sed s/"nameserver"/"ping -c1 "/|csh -f|grep icmp_seq`|cut -f4 -d=|sed s/"\."//|cut -b1,2' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp`${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'dns' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto dns else if ( ${progName} == 'dns' ) then goto dns endif # A nested ssh up test for a cluster of compute nodes node: #ssh -A wasp ./bin/fixnode ./bin/fixnode goto skipoldnode if ( ${doNode} == 'yes' ) then echo -n "node"${divider} foreach i ( ${theNodes} ) if ( `echo -n ${i} | sed s/^n//` >= 10 && `echo -n ${i} | sed s/^n//` <= 18) then echo -n ${UNDERLINE} endif ssh -Aq ${userName}@${MASTER} ssh -q ${userName}@${i} cat up > /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`echo -n ${i} | sed s/^n//`${UNGREEN} else echo -n ${RED}`echo -n ${i} | sed s/^n//`${UNRED} endif if ( `echo -n ${i} | sed s/^n//` >= 10 && `echo -n ${i} | sed s/^n//` <= 18) then echo -n ${UNUNDERLINE} endif echo -n ${divider} end echo skipoldnode: echo -n "nstt"${divider} ssh -q ${userName}@${MASTER} ./freenodes2 if ( $#argv != 0 || ${progName} == 'node' ) then echo -n '   ' else echo endif if ( $#argv != 0 ) then goto node else if ( ${progName} == 'node' ) then goto node endif endif # Do a ping test on each machine that fails every time. test: if ( ${doTest} == 'yes' || $1 == 'test' || ${progName} == 'test' ) then echo -n "dns "${divider} foreach i ( ${theGNUs} ${theSGIs} ) ( ssh ${userName}@${i} 'echo -n `ping -c1 256.256.256.256 | grep icmp_seq`|cut -f4 -d=|cut -b1,2' > /tmp/who_awake.tmp ) > & /dev/null if ( ${?} == 0 ) then echo -n ${GREEN}`cat /tmp/who_awake.tmp`${UNGREEN} else echo -n ${RED}dn${UNRED} endif echo -n ${divider} end if ( $#argv != 0 || ${progName} == 'test' ) then echo -n ' ' else echo endif endif if ( $#argv != 0 ) then goto test else if ( ${progName} == 'test' ) then goto test endif # A clock based on uptime and sleep clock: if ( $1 == 'clock' ) then setenv sleepTime 99999999999999999999 endif while( ${doClock} < ${sleepTime} ) echo -n `date`$divider`whoami`$divider`hostname -s`$divider`uptime | awk '{print($2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)}' | sed s/', '/"${divider}"/g | sed s/' $'//`${divider}" " && sleep 1 @ doClock = ${doClock} + 1 end @ doClock = 0 echo endsw end # Run the help command. commands: echo echo The following ${GREEN}${progName}${UNGREEN} commands are available: echo grep -a -H ':$' $0 | sed s/:/' '/g echo exit findidle: ssh ${userName}@${MASTER} pdsh -w `echo $theNodes | sed s/' '/','/g` "'top -b -n1 | head -1 | cut -f2,3,4,5,6 -d,'" |\ sed s/" ..:..,"// | sed s/".. min, "// | cut -f1,2,3,4 -d, > /tmp/who_awake.idle ( pdsh -l ${userName} -w `echo $theGNUs | sed s/' '/','/g` 'top -b -n1 | head -1 | cut -f2,3,4,5,6 -d,' | sed s/" ..:..,"// |\ sed s/".. min, "// | cut -f1,2,3,4 -d, >> /tmp/who_awake.idle ) > & /dev/null awk '{printf("%-10s %2s %6s %4s %7s %4s %4s %4s\n", $1,$2,$3,$4,$5,$6,$7,$8)}' /tmp/who_awake.idle | sort -nr -k2 -k6 exit makelinks: setenv theGoto `grep -a -H ':$' ${0} | cut -f2 -d: | grep $progName` if ( ${theGoto} != '' ) then echo run this with the who_awake command exit endif foreach i ( `grep -a -H ':$' ${0} | cut -f2 -d: | grep -v ssh` ) echo 'ln -sf '$0' '${i} | csh end ln -sf $0 who_awake exit neverGetsHere: