#!/usr/local/bin/tcsh -f
if ($#argv == 0 ) then
    echo " Usage: how 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

set datadir=`awk '$1=="datadir" {print $2}' $1`
if( "x$datadir" == "x") then
    echo datadir in config file not exists
    exit 1
endif
set datafile=`awk '$1=="datafile" {print $2}' $1`
if( "x$datafile" == "x") then
    echo datafile in config file not exists
    exit 1
endif

#     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 -w $prog | awk 'NF >0 {print "elapsed cpu time=" $7}; NF==0 {print "xxxxx"} '


	( rsh $f ls -l $datadir/$f/$datafile > /tmp/$$Size)  >& /tmp/$$ErrS

	 rm -f /tmp/$$Running 
#	 set size=` awk 'NF >0 {print $5}; NF==0 {print "xxxx"} /tmp/$$Size'`
          awk 'NF >0 {print $0}; NF==0 {print "xxxx"}' /tmp/$$Size

#	 echo this $cpu $size
  else
	echo $f seems to be dead
  endif	
end







