Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitoring processes. 1

Status
Not open for further replies.

theSeeker03

Programmer
Jan 16, 2004
17
US
I use ps command to manually make sure that my processes are running. But how can I automate it?

Ideally I'd like to be sent an email, or some other flag, when one of my processes stops running.
 
There are probably better/other ways, but this is one :

Code:
#!/bin/bash
process="MailScanner"
abc=`ps -ef |grep -v grep |grep $process`
if [ "$abc" = "" ]
then
        echo "process $process is not running" | mail -s "Dead Process" foo@bar.org
fi

--------------------------------------------------
Free Database Connection Pooling Software
 
Note the ` characters in the line containing "ps -ef" are backticks, not quotes ...

--------------------------------------------------
Free Database Connection Pooling Software
 
$( command ) is preferred to backticks since about 1992 and doesn't need special explanation. :)
 
It nests more easily, it's more readable, it's been available for 11 years and when you post an example using them you don't have to follow up your own post to point out that they are backticks and not quotes. :)
 
Code:
#step 0
abc=`ps -ef |grep -v grep |grep $process`
#step 1
abc=$(ps -ef |grep -v grep |grep $process)
#step 2
abc=$(ps -C $process)

look at your manpage, to find out, whether your 'ps' accepts the '-C' parameter.

seeking a job as java-programmer in Berlin:
 
hey sedj, dont you love people like ericbrunson in these forums!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top