procname is the name of the process you are looking to find.
cron version: (put in cron to run every 10 minutes)
#!/bin/ksh
#
PID=`ps -elf | grep procname | awk 'print { $4 }'`
if [ -z "$PID" ] ; then
print ""procname not found"
else
print "procname is running" /maildirectory/mail -s "procname is running" youremail@yourcompany.com
fi
exit 0
Non-cron version:
#!/bin/ksh
#
PID=" " # initialization
DONE="FALSE"
while [ $DONE = "FALSE" ]
do
PID=`ps -elf | grep procname | awk 'print { $4 }'`
if [ -z "$PID" ] ; then
print "procname not found"
else
print "procname is running" /maildirectory/mail -s "procname is running" youremail@yourcompany.com
fi
sleep 300
done
May contain minor syntax issues as I am not where I can test it. It is also possible to do this without awk if your version of grep can run silent. If so, grep will set a return code if the value is found.
That worked, I changed a few things though... the grep part and the if statement. added an exit 1 to exit after emailing.
#!/bin/ksh
#
PROCESS=" " # init alias
DONE="FALSE"
while [ $DONE = "FALSE" ]
do
PROCESS=`ps -elf | grep -c ex_part1`
if [ "$PROCESS" -eq 1 ] ; then
print "proc not found" >/dev/null
else
print "proc is running" >/tmp/foo.txt
mailx -s "The process has been detected!" mail@mail.com </tmp/foo.txt
mailx -s "The process has been detected!" mail@mail.com< /tmp/foo.txt
exit 1
fi
echo "sleeping......"
sleep 600
done
------------------------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.