Operating System - HP-UX
1834150 Members
2129 Online
110064 Solutions
New Discussion

Email notification when a service stops

 
David Greenhow
Advisor

Email notification when a service stops

We have a service running that returns the following message when active :
ps -ef|grep strs
root 7111 1 0 14:15:05 ? 0:43 /u01/data/app/PROD/appl/stream/strs/strs -a start.arg

What i would like to happen would be for the box to email out when the start.arg doesnt exist, but i have no idea on how to do this

If you guys could help me out in anyway, it would be greatly apreciated

Cheers

Dave
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Email notification when a service stops

Here's a general purpose one. You can create a 'cron' task for it. Assume that you want to look for a process called "myproc" and mail/page if it isn't running:

# [ -z "`UNIX95= ps -C myproc -o pid= -o comm=`" ] && mailx -s "myproc" is not running!" root < /dev/null

Change the 'myproc' to match the basename of the process that you're interested in monitoring. As shown, this generates a mail to 'root'.

In your case, the basename of your process is 'strs'. Substitute that string for 'myproc' in the above script.

Regards!

...JRF...
Chan 007
Honored Contributor

Re: Email notification when a service stops

Hi Dave,

You can write a script and keep in cron to monitor every minute

it will do

ps -ef |grep strs

NOP=$(ps -ef |grep strs|grep -v grep |wc -l)
if [ $NOP -lt 1 ]
then
MESS=$(echo "STRS proc not running")
mailx -s $MESS username
else echo working
fi

Chan
TwoProc
Honored Contributor

Re: Email notification when a service stops

You could just make the same script send the email... (but fwiw, I like James' posting better than this idea). This is only good b/c of its simplicity.

You can make the program wait for the strs to end, and then send the email. Like so:

#!/bin/ksh
/u01/data/app/PROD/appl/stream/strs/strs -a start.arg > logfile 2>&1 &
wait
echo "strs has stopped" | sendmail youruser@yourserver.com
We are the people our parents warned us about --Jimmy Buffett