Link to home
Start Free TrialLog in
Avatar of bhuvneshsharma
bhuvneshsharma

asked on

Checking for a process running

Hi All,
I want a script which runs as a cron and checks whether a process (Application Server) is running on the solaris box. If the process is down the script should give a mail to administrator.


Regards
ASKER CERTIFIED SOLUTION
Avatar of ecw
ecw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nisus091197
Nisus091197

I have just the thing for you, I'll look for it and send the script.

Regards, Nisus
http://www.omnimodo.com
A little more complete answer...

Here's what this does for you...
discriminates if progname happens to be part of another progname, a common situation
logs the messages (you do want to log, don't you?)


#!/bin/ksh
PROGNAME=myprogram
LOGFILE=/var/tmp/checkpid.log
PID=`ps -ef | grep -w myprogram | awk '{print $2}'`
if [ ! $PID ]
then
     /usr/local/scripts/mailit "Alert" "user@host.com" "dint find $PROGNAME in process table"
     echo `date "+%m/%d/%Y %H:%M:%S"` "Found $PROGNAME NOT RUNNING" >> $LOGFILE

else
     echo `date "+%m/%d/%Y %H:%M:%S"` "Found $PROGNAME running" >> $LOGFILE
fi

# end

Course you need a "mailit" wrapper for the above to work:

#!/bin/ksh
USAGE="usage: mailit <subject> <recipient> <message body>"
if [[ $# != 3 ]] then
print $USAGE
exit
fi
/usr/bin/mailx -r fromme@myhost.com -s "$1" $2 <<-EOF
$3
EOF

Caveat - you need to make sure your line breaks are right, no telling how this web site will wrap what I've posted.  You need a line return after each EOF above.  
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by ecw

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange