Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send notification email if process is not running

Tags:

shell

I am using the following shellscript to check running process in a cron job:

ps -ef|grep myprocess|grep -v "grep"

I then need to send an email if the result is empty(meaning process is not running), how do I script this?

like image 778
user121196 Avatar asked Sep 19 '25 05:09

user121196


2 Answers

One solution:

pgrep processname &>/dev/null && exit 0
echo |mail -s"Aiie, process processname not running!" [email protected]

Then put it in a crontab like already suggested. Of course, it means you must have the mail command installed.

like image 147
fge Avatar answered Sep 23 '25 10:09

fge


You can do it this way

PROCESS_FOUND=`ps -ef|grep myprocess|grep -v grep`
if [ "$PROCESS_FOUND" = "" ]
then
    #send mail from here ...Process not running
fi
like image 24
Raghuram Avatar answered Sep 23 '25 12:09

Raghuram