#!/bin/csh              

# February 17, 2003 
# choosehost - choose a host to use for a remote job. 
# This script rotates among servers listed in .BIRCHrhosts, 
# by choosing the host at the top of the list and moving
# it to the bottom.

# Make sure the remote host file exists
if (! -e $home/.BIRCHrhosts) cp $BIRCH/local/admin/BIRCHrhosts $home/.BIRCHrhosts
 
#Rotate the list, putting the current host to the bottom.
set HOST = `head -1 $home/.BIRCHrhosts`
set JOBID = $$
#tail +2 $home/.BIRCHrhosts > /tmp/.BIRCHrhosts.$JOBID
@ NUMLINES = (`wc -l $home/.BIRCHrhosts | sed -e "s/^[ ]*//" | cut -f1 -d" "`) - 1
tail -$NUMLINES $home/.BIRCHrhosts > /tmp/.BIRCHrhosts.$JOBID 
echo $HOST >> /tmp/.BIRCHrhosts.$JOBID
mv /tmp/.BIRCHrhosts.$JOBID $home/.BIRCHrhosts

# Write out the current host name
echo $HOST