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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With