Operating System - HP-UX
1834564 Members
3139 Online
110069 Solutions
New Discussion

Re: How to do it? ps -ef and send mail

 
SOLVED
Go to solution
violin_1
Advisor

How to do it? ps -ef and send mail

Hello,

I need to perform a check and send mail with results:

steps are:

1.do a command:
# ps -ef | grep MGR | grep erpmgr
=> if it returned a process id , that means running normally,
ex.
# ps -ef | grep MGR | grep erpmgr
erpmgr 19249 19232 0 15:08:43 pts/tc 0:01 FNDLIBR FND CPMGR FNDCPMBR sysmgr="" logfile=/u04/prodc
#

=> if it returned nothing , send a alert mail to SYSADMIN


2.I have a send mail scripts in HP-UX 11.0,
for example:
# sh /usr/local/bin/mimemail.sh < /mail_body

BUT I need some scripts to perform "ps -ef" , and call mimemail.sh to send alert mail if no process been found.

Thanks for any reply.

Violin.
7 REPLIES 7
T G Manikandan
Honored Contributor
Solution

Re: How to do it? ps -ef and send mail

you can do something like
x=`ps -ef|grep |wc -l`
if [ x -eq 0 ]
then
sendmail
else
echo
processes are runing fine
fi
Massimo Bianchi
Honored Contributor

Re: How to do it? ps -ef and send mail

I,
unfortunaly i have a small amount of time, to think to the check, but:

#!/sbin/sh

PID=$(ps -ef | grep MGR | grep erpmgr)

[ -n $PID ] && echo "No running MGR found" | mailx -s "ALERT: MGR NOT RUNNING" name.surname@yourdomain.com

#################END##################


Masssimo



Massimo Bianchi
Honored Contributor

Re: How to do it? ps -ef and send mail

Sorry, second line should be:

[ $PID ] && (echo "No running MGR found" | mailx -s "ALERT: MGR NOT RUNNING" name.surname@yourdomain.com )

####


TR: if PID is null, then no MGR is running, so send the mail
violin_1
Advisor

Re: How to do it? ps -ef and send mail

Hi TG,

your script is clear and simple for me.

x=`ps -ef|grep |wc -l`
if [ x -eq 0 ]
then
sendmail
else
echo
processes are runing fine
fi


but one more question:
I want to add a condition in if,
x=`ps -ef|grep |wc -l`
y=`ps -ef|grep |wc -l`

if x=0 and y>0 => how to do it in shell script?

Thx.

Violin.
T G Manikandan
Honored Contributor

Re: How to do it? ps -ef and send mail

something like

x=`ps -ef|grep oracle|grep pmon|wc -l`
y=`ps -ef|grep oracle|grep smon|wc -l`
if [ $x -eq 0 -a $y -eq 0 ]
then
sendmail
else
echo processes are runing fine
fi
violin_1
Advisor

Re: How to do it? ps -ef and send mail

Thanks for kindly replies,
I've solved my problem,

Thx again & Happy New Year!
Bill Hassell
Honored Contributor

Re: How to do it? ps -ef and send mail

I always get concerned when I see ps and grep used to find processes. grep will find all sorts of junk on the ps lines since grep doesn't know where to look. However, ps does so it makes sense to let ps do all the work. ps is even kind enough to report a failed ps search with a non-zero return code. All it takes is the UNIX95 flag. Here's a much more reliable version:

#!/usr/bin/sh
# Search for pmon and smon
if UNIX95= ps -C pmon > /dev/null
then
if UNIX95= ps -C smon > /dev/null
then
echo "all is well"
else
ps -u oracle | mailx "smon not running"
user@domain.com
fi
else
ps -u oracle | mailx "pmon not running"
fi

By using the -C option (requires the temp variable UNIX95=) ps will not find users with the name pmon3 or processes like upsmon.


Bill Hassell, sysadmin