#! /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 divider ${BLUE}'|'${UNBLUE} setenv userName `grep 0:0 /etc/passwd |grep Love |cut -f1 -d:` # Most of these tests write a couple of bytes to /tmp/fastcheck.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 no setenv doNFS yes setenv doUser yes setenv doLoad yes setenv doWeb yes setenv doDNS yes setenv doNode yes setenv doNnam yes # doTest fails on purpose. setenv doTest no # Clock ticker time in seconds, in order to give the network a rest setenv sleepTime 30 # Initialize ticker and command list. No need to change this. set doClock = 0 setenv theCommands `grep -a -H ':$' ${0} | cut -f2 -d:` # Machine name lists are set in the loop for on the fly changes. setenv theGNUs `mygnu` setenv theGNUs `echo ${theGNUs} | sed s/' '/','/g` setenv theSGIs `mysgi` setenv theSGIs `echo ${theSGIs} | sed s/' '/','/g` setenv theNodes `mysnode` setenv theNodes `echo ${theNodes} | sed s/' '/','/g` setenv MASTER `mysmaster` setenv pdshCommand 'pdsh -l'${userName}' -w' setenv theCommands `grep -a -H ':$' ${0} | cut -f2 -d:` if ( $progName == 'commands' || $progName == 'help' || $progName == 'node' || $progName == 'nup') then goto $progName endif if ( $1 == 'commands' || $1 == 'help' || $1 == 'node' || $1 == 'nup') then goto $1 endif # Print the name list names: if ( ${doNames} == 'yes' && ${1} != 'node' ) then echo -n "name"${divider} echo `echo -n ${theGNUs}','${theSGIs} | sed s/','/'\n'/g | cut -b 1,2 | sed s/^/${YELLOW}/ |\ sed s/'$'/${UNYELLOW}${divider}/g | sort` | sed s/' '//g echo -n "pdsh"${divider} ( echo -n `${pdshCommand}${theSGIs}','${theGNUs} 'echo up' | sort | cut -b 1,2 | sed s/^/${YELLOW}/ |\ sed s/'$'/${UNYELLOW}${divider}/g` | sed s/' '//g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp && echo endif if ( $1 == 'names' || $progName == 'names' ) then exit endif 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' || $#argv != 0 || ${progName} == 'ssh' ) then echo -n "ssh "${divider} ( echo -n `${pdshCommand}${theSGIs}','${theGNUs} 'echo up' | sort | cut -b 1,2 | sed s/^/${GREEN}/ |\ sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp if ( $#argv != 0 || ${progName} == 'ssh' ) then echo -n '   ' goto names else echo endif endif # An up test based on nfs access nfs: if ( ${doNFS} == 'yes' || $#argv != 0 || ${progName} == 'nfs' ) then echo -n "nfs "${divider} ( echo -n `${pdshCommand}${theSGIs}','${theGNUs} 'cat /nfs/fs/prog/up' | sort | cut -f2 -d':' | cut -b 2,3 |\ sed s/^/${GREEN}/ | sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp if ( $#argv != 0 || ${progName} == 'nfs' ) then echo -n '   ' goto names else echo endif endif # Get the number of users on each machine from the uptime output. user: if ( ${doUser} == 'yes' || $#argv != 0 || ${progName} == 'user' ) then echo -n "user"${divider} ( echo -n `${pdshCommand}${theSGIs}','${theGNUs} 'uptime | cut -d, -f3' | sort | cut -f2 -d':' |\ cut -b 3,4 | sed s/' '/'%'/ | sed s/^/${GREEN}/ | sed s/'$'/${UNGREEN}/g` |\ sed s/' '/${divider}/g | sed s/'%'/' '/g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp echo -n ${divider} if ( $#argv != 0 || ${progName} == 'user' ) then echo -n '   ' goto names else echo endif endif # Get the load on each machine from the uptime output. load: if ( ${doLoad} == 'yes' || $#argv != 0 || ${progName} == 'load' ) then echo -n "load"${divider} ( echo -n `${pdshCommand}${theSGIs}','${theGNUs} 'uptime | cut -f4 -d, | cut -f2 -d: | cut -b2,4' | sort |\ cut -f2 -d':' | cut -b 2,3 |\ sed s/^/${GREEN}/ | sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp if ( $#argv != 0 || ${progName} == 'load' ) then echo -n '   ' goto names else echo endif endif # An up test based on web access web: if ( ${doWeb} == 'yes' || $#argv != 0 || ${progName} == 'web' ) then echo -n "web "${divider} ( ${pdshCommand}${theGNUs} 'lynx -source http://proclus.gnu-darwin.org/up' > /tmp/fastcheck.tmp ) >\ & /dev/null ( ${pdshCommand}${theSGIs} '/usr/freeware/bin/lynx -source http://proclus.gnu-darwin.org/up' >>\ /tmp/fastcheck.tmp ) > & /dev/null echo -n `cat /tmp/fastcheck.tmp | sort | cut -f2 -d':' | cut -b 2,3 |\ sed s/^/${GREEN}/ | sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g if ( $#argv != 0 || ${progName} == 'web' ) then echo -n '   ' goto names else echo endif endif dns: # Test access to name servers with ping on each machine. if ( ${doDNS} == 'yes' || $#argv != 0 || ${progName} == 'dns' ) then echo -n "dns "${divider} ( ${pdshCommand}${theSGIs}','${theGNUs} 'grep nameserver /etc/resolv.conf|head -1| sed s/"nameserver"/"ping -c1 "/|csh -f|grep icmp_seq' > /tmp/fastcheck.tmp ) > & /dev/null echo -n `sort /tmp/fastcheck.tmp | cut -f4 -d=| cut -b1,3 |\ sed s/^/${GREEN}/ | sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g if ( $#argv != 0 || ${progName} == 'dns' ) then echo -n '   ' goto names else echo endif endif # A nested ssh up test for a cluster of compute nodes node: if ( ${doNode} == 'yes' || $#argv != 0 || ${progName} == 'node' ) then if ( ${doNnam} == 'yes' ) then echo -n "nnam"${divider} foreach i ( `echo ${theNodes} | sed s/','/' '/g` ) if ( `echo -n ${i} | sed s/^n//` >= 10 && `echo -n ${i} | sed s/^n//` <= 18) then echo -n ${UNDERLINE} endif echo -n ${YELLOW}`echo -n ${i} | sed s/^n//`${UNYELLOW} if ( `echo -n ${i} | sed s/^n//` >= 10 && `echo -n ${i} | sed s/^n//` <= 18) then echo -n ${UNUNDERLINE} endif echo -n ${divider} end setenv doNnam no echo endif echo -n "nup "${divider} ( echo -n `ssh $userName@$MASTER ${pdshCommand}${theNodes} 'echo up' | sort | cut -b 2,3 | sed s/^/${GREEN}/ |\ sed s/'$'/${UNGREEN}${divider}/g` | sed s/' '//g > /tmp/fastcheck.tmp ) > & /dev/null cat /tmp/fastcheck.tmp echo echo -n "nstt"${divider} ssh -q ${userName}@${MASTER} ./freenodes2 if ( $#argv != 0 || ${progName} == 'node' ) then echo -n '  ' goto node else echo endif endif exit help: echo echo 'Maybe should write something for this spot?' commands: echo echo The following ${GREEN}${progName}${UNGREEN} commands are available: echo grep -a -H ':$' $0 | sed s/:/' '/g echo exit makelinks: setenv theGoto `echo ${theCommands} | grep $progName` if ( ${theGoto} != '' ) then echo run this with the fastcheck 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 fastcheck exit neverGetsHere: