#! /bin/csh -f

if ($#argv < 4) then
	echo ""
	echo "usage: runreg.csh machine net day year"
	echo "       e.g., runreg.csh doc eura 223 98"
	echo ""
        exit
endif

set host = $1
set net = $2
set day = $3
set yr = $4

if($host == "doc") then
 set sfx = "_d"
 set loadmax = "12"
endif

if($host == "domino") then
 set sfx = "_m"
 set loadmax = "12"
endif

if($host == "josh") then
 set sfx = "_j"
 set loadmax = "32"
endif

if($host == "baja") then
 set sfx = ""
 set loadmax = "02"
endif

if($net == "cors") then
 set extra = "-l links.oct"
 set opt = "regzen49$sfx[1].opt"
else
 set extra = ""
 set opt = "regzen25_hpgn$sfx[1].opt"
endif

### check load average

echo "" >! /net/josh1/working/daily/$net[1].$host[1].log

start:
set load = `rsh $host -n uptime | cut -dg -f2 | cut -c4,6`
if ($load > $loadmax) then
        echo Load average $host too high, waiting... >>& /net/josh1/working/daily/$net[1].$host[1].log
        sleep 900
        goto start
else

echo Starting $net 19$yr[1] $day on $host >>& /net/josh1/working/daily/$net[1].$host[1].log
rsh $host -n /net/domino/matthijs/hpgn/bin/reggamit.csh -o $opt -s 19$yr[1] $day -p $net $extra >>& /net/josh1/working/daily/$net[1].$host[1].log &
