#!/bin/bash
#==============================================================
# check_screenlogdLog.bash
#
# ARGUMENT:
#
# USE:
#   will be called by screenlogd.bash to check for createDetachedScreen.bash errors.
#   these errors may indicate something fix-able about the iocs in question 
#   for example, needing the ts port reset.
#
#   creates file \tmp\screenlogdLogErrList.log
#   which can be examined, and will emailed by screenlogd.bash
#
# Facility:  SLAC/LCLS
#
# Auth:  19-Aug-2010, Judy Rock (jrock)
# Rev:   dd-mmm-yyyy, Reviewer's Name (USERNAME)
#
# Rem:   Screen logging management
#----------------------------------------------------------------------------
# Mod:
#==============================================================
if [ -d /afs/slac/g/lcls ]; then
   export LCLS_ROOT=/afs/slac/g/lcls
   export SCREEN_HOST="lcls-dev2"
else
   export LCLS_ROOT=/usr/local/lcls
   export SCREEN_HOST="lcls-daemon1"
fi

source $LCLS_ROOT/tools/script/ENVS.bash
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" > /tmp/screenlogdLogErrList.log
echo "CHECKING /tmp/screenlogd.log" >> /tmp/screenlogdLogErrList.log
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log
echo THESE IOCs NEED MANUAL CHECKING:  >> /tmp/screenlogdLogErrList.log
grep "please check manually" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo IOC_DATA/iocname directory check failure:  >> /tmp/screenlogdLogErrList.log
grep "directory does not exist" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo pingability failure:  >> /tmp/screenlogdLogErrList.log
grep "is not pingable" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo screen process creation failure:  >> /tmp/screenlogdLogErrList.log
grep "create SCREEN process FAILED" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo socket creation failure:  >> /tmp/screenlogdLogErrList.log
grep "create SCREEN socket FAILED" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo IOC not found in screeniocs file:  >> /tmp/screenlogdLogErrList.log
grep "IOC not found in screeniocs file" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo calling with soft IOC failure:  >> /tmp/screenlogdLogErrList.log
grep "is a soft ioc" /tmp/screenlogd.log >> /tmp/screenlogdLogErrList.log
echo " " >> /tmp/screenlogdLogErrList.log

echo "=============================================="  >> /tmp/screenlogdLogErrList.log
echo "checking done"  >> /tmp/screenlogdLogErrList.log
