Scripting is very, very useful. Don’t make the same mistake I did and wait 5 years into you career to start learning! In the example below, I’m using the ‘ps -aux’ command piped into grep to determine if a process is still running. for my example I’m using Firefox, but intend to use this with a Asterisk phone system. Every minute cron will launch my script to see if Asterisk is still running. If it is, it will do nothing. If it isn’t, then it will attempt to restart asterisk and notify the Administrator. I hope this example helps someone!
# Variables Section
# list process to monitor in the variable below.
# varible checks to see if $PROGRAM1
# is running.
APPCHK=$(ps aux | grep -c $PROGRAM1)
# $Company & $SITE variables are for populating the alert email
# $SUPPORTSTAFF is the recipient of our alert email
# 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.
if [ $APPCHK = '0' ];
echo mail -s “Asterisk PBX at $COMPANY $SITE may be down” $SUPPORTSTAFF < /dev/null
echo “$PROGRAM1 is running $APPCHK processes” >> asterisk-check.log