Process Monitor and Email Alert In One Line

ps aux|grep PROCESSNAME > /dev/null; if [ $? -ne 0 ]; then echo "Process is not running!" | mail -s "ALERT: Process is not running" alert@yourdomain.com; fi

Substitute PROCESSNAME with the name of the daemon or script you want to monitor. This is good if you have a long running script that you want to be alerted of when it finishes (you can do more within the then clause of the if construct). It is best run from cron, perhaps every 5 mins, something like:

*/5 * * * * ps aux|grep PROCESSNAME > /dev/null; if [ $? -ne 0 ]; then echo "Process is not running!" | mail -s "ALERT: Process is not running" alert@yourdomain.com; fi

Wednesday, September 21st, 2011 Bash, Linux, Unix

Leave a Reply