Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

There is a process running on our server that fails every once in a while. I'd like to receive some sort of email notification whenever that happens. Is there a simple way to set that up?

share|improve this question

migrated from stackoverflow.com Jun 20 '10 at 2:30

This question came from our site for professional and enthusiast programmers.

    
by fails do you mean exits completely or gets stuck or simply stops performing its function? –  SpliFF Jun 19 '10 at 3:44
    
it exits completely, usually killed by the OS –  k-g-f Jun 19 '10 at 5:03

4 Answers 4

The simplest way to do it would probably be this one-liner (inspired by SpliFF's answer):

failing_process || mail -s 'Process failed' localpart@example.com

For a more sophisticated monitoring of your system (and not only a single process), take a look at Nagios, monit and all the other well-known monitoring tools. They usually also support notifications by other means than just by email.

For a single system, monit is probably the most suitable solution.

share|improve this answer

Have a cron job that executes

ps -A | grep INSERTPROCESSNAME

And sees whether what you want is there

Then runs some script to send off an email. You can write the script sender however you want, using php, python - anything with an SMTP wrapper.

Alternatively, you can use http://www.postageapp.com and send a curl request to it.

share|improve this answer
    
thanks. rather than a cron job, I was wondering if there was a way to trigger the job when the process exits. –  k-g-f Jun 19 '10 at 5:05

if the process is exiting completely you can do it in bash:

myprocess &
wait
echo "process details" | mail -s "process failed" email@example.com
share|improve this answer

I think there is an nagios check for processes. That means you have to setup nagios or you can do it the old fashion way, run a cron every minute to check by name, if the process still exists. If no process is found by that name then you have your answer.

IF the process that is running uses a tcp/udp port. You can listen on that port and when that fails, you get an email. I think you can use a CRON here as well.

The processes don't get killed without any reason and there is always evidence why the process failed. Is there a anything in the log files why the process was killed?

-N

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.