#!/usr/local/bin/tcsh  -f
if ($#argv == 0 ) then
    echo " Usage: seerunjob configFile [host host ...]"
    exit 1
endif
if (! -f $1)  then
    echo $1 not exists
    exit 1
endif
#     get execution prog path name
set progpath=`awk '$1=="prog" {print $2}' $1`
if ( x$progpath == "x") then
    echo prog in config file not exists
        exit 1
    else if(! -f $progpath) then
        echo prog path $progpath not exists
        exit 1
    endif
endif

#    get last name of the path
    set prog=$progpath:t
#   echo  $prog

#     get ps usage
set ps=`myps`
if ( "x$ps" == "x" ) then
    echo myps should be modified
    exit 1
endif
#  get alive file 
# 
set alive=`awk '$1=="alive" {print $2}' $1`
if ( "x$alive" == "x" ) then
    echo alive in config file not exists
    exit 1
endif


@ n = 0
foreach f(`cat $alive`)
  if(  $#argv >= 2) then
    if(`echo "$argv[2*]" | gawk '{if(index($0, h) >0 ) print "x";else print "y"}' h=$f -` == "y") continue
    endif
@ n += 1
  echo " "
 echo $n " " $f
 seeifdead  $f

 if( $status == 0 ) then 		
	 rsh $f $ps | grep $USER > /tmp/$$Running
	 cat /tmp/$$Running | grep  $prog
	 rm -f /tmp//$$Running 
  else
	echo $f seems to be dead
  endif	
end

