Tuesday, 24 July 2012

Process Monitoring Scripts in Linux



#!/bin/bash
#set -x
#
#Variable secetion 
#=====================================================
#list process to monitor in the variable below;
PROGRAM1="firefox"
#Variabele check to see if $PROGRAM1
#is running
APPCHK=$(ps aux | grep -c $PROGRAM1 )
#$Company & Site variable are for populating the alert email
COMPANY="Hungama"
SITE="JMX"
# $SUPPORTSTAFF is the recipient of our alert email
SUPPORTSTAFF="manish.bhandari@fosteringlinux.com"
#=======================================================
# The ‘if’ statement below checks to see if the process is running
# with the ‘ps’ command.  If the value is returned as a ’0′ then
# an email will be sent and the process will be safely restarted.
#
echo "COUNT IS " $APPCHK

if [ $APPCHK -eq '1' ];then
echo mail -s "Manish PBX at $COMPANY $SITE may be down " $SUPPORTSTAFF >> notrunning.log
else
echo "$PROGRAM1 is running $APPCHK processes" >> manish-check.log
fi
echo $APPCHK
exit