monitor_fgl.ksh
#!/bin/ksh ########################################################################################################### ############# # DBA TEAM - initial version # 03/18/2019 - Made it dynamic to pick the FGL home ########################################################################################################### ############# ##set -x # # This job will monitor foglight and attempt to restart it if it # is not running. It will send email notification. # REL_2 # Envir. . $HOME/.profile > /dev/null if [ -a .kshrc ]; then . ./.kshrc fi export OS=$(uname) BASE=$(dirname $0) ## LOGDIR="/oracle/dba/output/generic" dte=`date +%Y%m%d` HOST=`hostname -s` ## logf=${LOGDIR}/${HOST}_Foglight_Stat_${dte}.log logf=/tmp/${HOST}_Foglight_Stat_${dte}_$$.log # SENDER_EMAIL_ID="dg.Adminemail_baci_oracle_dba@test.com" ## FGL_STATE=/oracle/dba/foglight/fgl_5/state/default find / -type d \( -name proc -o -name banktools -o -name efs -o -name dbacl -o -name run -o -name ".efs" -o -name home -o -name vol \) -prune -o -name "fgl_5" -print 2>&1 | grep -v "Permission denied" > /tmp/fog_te st_$$.lst for i in `cat /tmp/fog_test_$$.lst` do FGL_OWNER=`ls -ld $i |cut -d " " -f 3` if [ "$FGL_OWNER" = "$USER" ] then export FGL_HOME=$i fi done if [ $? -ne 0 ]; then echo "Not able to identify the FGL home - Please Investigate" exit 1 fi if [ -z $FGL_HOME ]; then echo "Not able to identify the FGL home - Please Investigate" exit 1 fi FGL_STATE=$FGL_HOME/../../foglight/fgl_5/state/default MAILDATE=$(date '+%m%d%Y_%H%M') TOA="test.com" EMAIL="dg.oracle_hosting_services_-_non_exa@${TOA}" #MESSAGE="Foglight Not Running - Attempt to Restart Failed" #MESSAGE="Foglight Was Not Running - Restarted" MSG_SUBJECT="Test email with file" #send_mail () { # if [ "$OS" == "Linux" ]; then # if [ `uname -r | cut -d. -f3 | cut -d- -f1` -le 18 ]; then # (echo $MESSAGE ) | mail -s "$HOST - $MSG_SUBJECT" $EMAIL -- -f $SENDER_EMAIL_ID # else # (echo $MESSAGE) | mailx -s "$HOST - $MSG_SUBJECT" -r $SENDER_EMAIL_ID $EMAIL # fi # else # (echo $MESSAGE ) | mailx -s "$HOST - $MSGTEXT" -r $SENDER_EMAIL_ID $EMAIL # fi #} if [ -r $FGL_STATE/.*.pid ]; then cat `ls $FGL_STATE/.*.pid|tail -1` > /tmp/fgl_pcheck_$$.lst FGL_PID=`cat /tmp/fgl_pcheck_$$.lst` ## FGL_PID=`cat $FGL_STATE/.*.pid` ## ps -ef | grep $FGL_PID | grep -v grep | grep -i fog > /dev/null if [ $? -ne 0 ]; then printf "Foglight not running PID = $FGL_PID \n" >>${logf} 2>> ${logf} printf "Restarting ........................ \n" >>${logf} 2>> ${logf} $FGL_HOME/bin/fglam -Xint -d >>${logf} 2>> ${logf} sleep 60 FGL_PID=`cat $FGL_STATE/.*.pid` ps -ef | grep $FGL_PID | grep -v grep > /dev/null if [ $? -ne 0 ]; then # MESSAGE="Foglight Not Running - Attempt to Restart Failed - Please Investigate" # MSG_SUBJECT="Foglight Restart Failed" #send_mail echo "Foglight Not Running - Attempt to Restart Failed - Please Investigate" exit 1 else echo "Foglight Was Not Running - Restarted Successfully" # MSG_SUBJECT="Foglight Restarted" #send_mail fi else printf "Foglight is running PID = $FGL_PID \n" >>${logf} 2>> ${logf} fi else printf "Foglight not running .............. \n" >>${logf} 2>> ${logf} printf "Restarting ........................ \n" >>${logf} 2>> ${logf} $FGL_HOME/bin/fglam -Xint -d >>${logf} 2>> ${logf} sleep 60 FGL_PID=`cat $FGL_STATE/.*.pid` ps -ef | grep $FGL_PID | grep -v grep > /dev/null if [ $? -ne 0 ]; then # MESSAGE="Foglight Not Running - Attempt to Restart Failed - Please Investigate" # MSG_SUBJECT="Foglight Restart Failed" echo "Foglight Not Running - Attempt to Restart Failed - Please Investigate" exit 1 #send_mail else # MESSAGE="Foglight Was Not Running - Restarted Successfully" echo "Foglight Was Not Running - Restarted Successfully" MSG_SUBJECT="Foglight Restarted" #send_mail fi fi # exit