#!/bin/bash
#==============================================================
if [ -d /afs/slac/g/lcls ]; then
   export SCREEN_HOST=lcls-dev2
   export LCLS_ROOT=/afs/slac/g/lcls
else 
   export SCREEN_HOST=lcls-daemon1
   export LCLS_ROOT=/usr/local/lcls 
fi

# for each soft ioc with a socket file, make sure there's a screenlog.0
siocs=`grep ^sioc-.*$SCREEN_HOST $IOC_SCREEN/screeniocs | awk '{print $1}'`
echo LIST OF SOFT IOCS > /tmp/siocsMissingScreenlog.txt
echo - WITH SCREEN PROCESS AND >> /tmp/siocsMissingScreenlog.txt   
echo - MISSING SCREENLOG.0 FILE >> /tmp/siocsMissingScreenlog.txt

for i in $siocs
do
   numPROCS=`ssh $SCREEN_HOST  -l laci ps -ef | grep " $i" | grep SCREEN | wc -l`

   if [ $numPROCS -gt 0 ]; then
      if [ -e $IOC_DATA/$i/screenlog.0 ]; then
         echo screenlog file exists for soft IOC $i
      else
         echo NO screenlog file exists for soft IOC $i
         echo $i >> /tmp/siocsMissingScreenlog.txt
      fi

   fi
done
echo END OF LIST >> /tmp/siocsMissingScreenlog.txt
#cat /tmp/siocsMissingScreenlog.txt  | Mail -s "SIOCs missing screenlog.0 files" jrock@mccdev.slac.stanford.edu 

