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


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

if ($2 =~ -*) then
  set   tailopt=$2
  shift
else 
  set  tailopt=
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 $n " " $f
 seeifdead  $f
 echo " "
 if( $status == 0 ) then 		
	 rsh $f tail $tailopt  $datadir/$f/$datafile 
	 echo " "
  else
	echo $f seems to be dead
  endif	
end










