#!/bin/bash
#
printf "\n\n\tThis script will restart the Channel Watcher daemons\n"
printf "\tfor either LCLS or Facet\n"
printf "\n\t [LCLS | FACET] -> "
read ans
ans=`echo $ans | tr '[:lower:]' '[:upper:]'`

if [ "$ans" = LCLS ] 
  then
	SHOST=lcls-daemon2
	SUSER=laci
  elif [ "$ans" = FACET ]
    then
 	SHOST=facet-daemon1
	SUSER=flaci
  else
     exit
fi

SLIST=`ssh -qxl $SUSER $SHOST ls /etc/rc3.d/S*st.cw*`
for x in $SLIST
do
	y=`echo $x | awk -F/ '{print $4}'`
	printf "\n\tRestarting  $y\n"
 	ssh -qxl $SUSER $SHOST $x restart
	sleep 1
done