#!/bin/csh if ( $#argv == 0 || x"$1" == "x-h" ) then cat - <& /dev/null if ( $status == 1 ) then echo Cannot find command $1 exit 1 endif touch pollmach_is_running set commandtorun="$*" if ( $?usebusyflag ) then echo Interactive loop mode... while ( 1 ) echo Waiting... while ( ! -e busy && ! -e stop && ! -e stoppoll && ! -e error ) sleep 2 end if ( -e stop || -e stoppoll || -e error ) then echo exiting break endif echo Running command $commandtorun < /dev/null rm busy end rm -f pollmach_is_running rm -f stop stoppoll busy exit else if ( ! -e $machinefile ) then echo Warning: File $machinefile not found, running in single machine mode... echo for more information on the multiple machine mode type chl while (! -e stoppoll) find . -name wait |& grep -q wait if ($status == 1) then if ( $?exitwhendone ) goto myexit while (-e ready) sleep 3 end touch ready while (-e ready) sleep 3 end endif pushd `find . -name wait -printf "%A@ %p\n" |& sed 's+/wait++g' | sort -n -r | tail -n -1 | awk '{print $2}'` >& /dev/null rm -f wait echo Running in $PWD $commandtorun < /dev/null echo Done running in $PWD popd >& /dev/null end else if ( $?usesema ) then rm -f pollmachload*.tmp grep -v -e '^#' -e '^set' $machinefile | awk 'BEGIN {n=1;} {print "0" > "pollmachload"n".tmp"; n++;}' endif set waitbetweenpoll=`grep '^set ' $machinefile | getvalue waitbetweenpoll` while (! -e stoppoll) find . -name wait |& grep -q wait if ($status == 1) then while (-e ready) sleep 3 end touch ready while (-e ready) if (-e stoppoll) goto myexit sleep 3 end endif if ( $?usesema ) then while (1) if (-e stoppoll) goto myexit grep -q '^0$' pollmachload*.tmp if ( $status == 0 ) break sleep $waitbetweenpoll end set nodenumber=`grep -l '^0$' pollmachload*.tmp | tail -n -1 | sed -e 's/pollmachload//g' -e 's/.tmp//g'` set node=`grep -v -e '^#' -e '^set' $machinefile | tail -n +$nodenumber | head -1 | sed 's/^.*+//g'` set curdir=`find . -name wait -printf "%A@ %p\n" |& sed 's+/wait++g' | sort -n -r | tail -n -1 | awk '{print $2}'` >& /dev/null rm -f ${curdir}/wait (echo 1 >! pollmachload${nodenumber}.tmp ; \ pushd $curdir; \ echo Running in $PWD on $nodenumber ; \ $commandtorun "$node" < /dev/null ; \ echo Done running in $PWD on $nodenumber; \ popd >& /dev/null ; \ echo 0 >! pollmachload${nodenumber}.tmp ) & sleep $waitbetweenpoll else while ( 1 ) if (-e stoppoll) goto myexit set node=`minload -m $machinefile` if ( "$node" != "none" ) break sleep $waitbetweenpoll end pushd `find . -name wait -printf "%A@ %p\n" |& sed 's+/wait++g' | sort -n -r | tail -n -1 | awk '{print $2}'` >& /dev/null rm -f wait echo Running in $PWD on $node ($commandtorun "$node" < /dev/null ; echo Done running in $PWD on $node) & popd >& /dev/null sleep $waitbetweenpoll endif end endif endif myexit: rm -f stoppoll if (-e ready) then rm -f ready endif if ( $?waitforchildren ) then wait endif rm -f pollmach_is_running