#!/bin/csh -f
if ( $#argv != 1 ) then
	echo "Usage: ./execflesh_one HostList_path"
	exit
endif
set how = ` awk 'NR==2 {print $2;exit}' exectemplate `
loop: 
 echo  "Give a list of hostnames for flesh."
 echo  "They must be some of those listed in $1"
 set hostname="$<"
 echo "You gave: "
 echo $hostname
 echo "Is it OK?; Enter y if yes"
 set yesno=$<
 if ( x$yesno != "xy" ) goto loop
 set hostname = `echo $hostname | awk 'BEGIN{RS=" "}; {print}' `
 @ nhost = $#hostname;
 echo  "You gave $nhost hosts";
 foreach exechost ( $hostname )
       echo $exechost;
       set numb = ` awk '$2==host {printf("%3.3d "), $1}' host=$exechost  $1 `
       if(  $#numb != $nhost )  then
         echo "some of $exechost not exist in $1"
	 goto loop
       endif
 end

 echo "all hosts have been verified ; they are in $1"

 set prevhost = ""
 foreach exechost ( $hostname )
#       echo $exechost;
    if( $exechost != $prevhost ) then
       set prevhost=$exechost;
       set numb = ` awk '$2==host  {printf("%3.3d "), $1}' host=$exechost $1 `;
       @ nhost = $#numb;
       while( $nhost >0 ) 
        echo $numb[$nhost]  $exechost;
        sed "/^[^#]/s/__/$numb[$nhost]/g"   exectemplate  > exec;
        chmod +x exec;
        echo command used at $exechost is ;
        awk 'substr($1,1,1) != "#"' ./exec
        if( $how == "sge" ) then
          qsub  $COSMOSTOP/UserHook/DisPara/$FLESHDIR/exec;
        else
           ssh $exechost  $COSMOSTOP/UserHook/DisPara/$FLESHDIR/exec;
        endif
        @ nhost--;
        sleep 1;
       end
    endif
  end


























































