#!/usr/local/bin/tcsh -f
#  distjob: distributed jobs over many pentium machines
#
#   pwd is n.g
echo "enter first or add depending on the run is first or adding data"
set add=$< 
if(x$add == "x")  then
	echo "add= " $add " invalid"
	exit 1	
else if ($add == "first") then
else if ($add == "add") then
else
	echo "add= " $add " invalid"
	exit 1
endif	
echo "enter directory name to store data"
set dir=$<
echo $dir is the Data directory
if( ! -d $dir) then
	echo it not exist
	exit 1
endif

set xx=`echo $cwd`
foreach mac(`cat alive`)
# echo $mac	
onintr -
#   save .rhosts if exists
# if(-f ~/.rhosts) mv ~/.rhosts ~/.rhostsSave
#   if we give complete host name in .rhosts, error takes place.
#   set hostdom=`niutil -read / /locations/resolver | grep domain`
#   set host=`hostname`.$hostdom[2]
  set host=`hostname`
# 
#   put current hostname in .rhosts
# echo $host >! ~/.rhosts
# cat ~/.rhosts
# echo " above is current machine where I am"


#  make a command  for a run 
#  randomly choose an integer 
set u=`echo "x" | gawk  '{srand(); print int(rand()*100005+1); exit}'  `
# echo $u, " a random number"
# 
gawk '$1=="InitRN" {print " InitRN=", (uu+10), uu*39}; $1!="InitRN" {print}' uu=$u  $dir/param  > Param/$mac
if ($add == "add") then
  echo "cd $xx; call < Param/$mac | gzip  >> $dir/$mac   & " > ~/Com/execcos$mac
else
  echo "cd $xx; call < Param/$mac | gzip >  $dir/$mac   & " > ~/Com/execcos$mac
endif
chmod +x  ~/Com/execcos$mac

# cat ~/Com/execcos
# echo " above is rsh command"
#   if interuptted goto file delete-section

onintr delete

echo "¹ԤˤϤޤ"
limit cpu  30
 rsh $mac  ~/Com/execcos$mac  &
delete:
#            disable double interupt   
	onintr -
#	rm -f ~/.rhosts
#	 if(-f ~/.rhostsSave) mv ~/.rhostsSave ~/.rhosts
         unlimit cpu
	echo "$mac now run"
	sleep 1
end







