Quick Script to monitor a process

October 22, 2008

There are numerous programs such as monit which are widely used as to monitor processes and take certain actions in case of different events.

Here is a little tip as to quickly monitor an service/process if you aren’t wanting to go through the hassle to configure monit


r=$(ps cax |grep -c NAME_PROCESS)

if [ $r -eq 0 ]; then service NAME_PROCESS restart echo “NAME_PROCESS has crashed”  | mail -s “monitoring SERVERID” your_Email_Address fi

Save this as an executable, set up a cron and voila :-)

Good luck,