Operating System - HP-UX
1753359 Members
6338 Online
108792 Solutions
New Discussion

Re: process monitoring script help...

 
SOLVED
Go to solution
sekar sundaram
Honored Contributor

Re: process monitoring script help...

ok, lets check this idea little later...
for testing i used this option:
Count=`ps -ef | grep -i $i | grep -v grep | wc -l`

its mailing fine. the second question is what the issue. ie, mailing once when all processes are running fine. i am thinking this idea:
1. processes goes down, it gets updated into the process-to-be-mailed file, it gets mailed.
2. in every loop, it checks for the same list of processes, so, if the file size zero(means, all processes are running fine) then one mail should be sent as "All processes are running fine at `date`"
3. in other loops, it should not send an email even if file size is zero. it looks like we should use a "flag".

please check this idea and help me implement(i am bit good at troubleshooting if there is any script, but not good in writing a new script).
James R. Ferguson
Acclaimed Contributor

Re: process monitoring script help...

Hi (again) Sekar:

> the second question is what the issue. ie, mailing once when all processes are running fine. i am thinking this idea:
1. processes goes down, it gets updated into the process-to-be-mailed file, it gets mailed.
2. in every loop, it checks for the same list of processes, so, if the file size zero(means, all processes are running fine) then one mail should be sent as "All processes are running fine at `date`"
3. in other loops, it should not send an email even if file size is zero. it looks like we should use a "flag".

For this you could use something like:

# cat ./mymonitor
#!/usr/bin/sh
RSLT=/tmp/MAILER
INPF=/tmp/PROCLIST
WAIT=10 #...wakeup interval in seconds...
OK=0
while true
do
cat /dev/null > ${RSLT}
while read PROC
do
[ -z "$(UNIX95= ps -C ${PROC} -opid=)" ] && echo ${PROC} >> ${RSLT}
done < ${INPF}
if [ -s "${RSLT}" ]; then
echo mailx -s "processes not running" ssundaram22@xyz.com < ${RSLT}
OK=0
elif [ "${SENT}" = 0 ]; then
echo mailx -s "all processes ok" ssundarm22@xyz.com < /dev/null
OK=1
fi
sleep ${WAIT}
done
exit

...

This will run infinitely, waking up every 'WAIT' seconds. Kill the script with a Control_C interrupt. You will need to adjust the variable values to your needs. You will also need to remove the 'echo' statement before the 'mailx' command when you are ready to actually send mail. Using the 'echo' is useful in debugging since you can see what's happening as you start and stop various processes in another session.

When everything works the way you want, you could encapsulate this script in a run-control/start-up wrapper to "daemonize" it.

Regards!

...JRF...