Solved

Checking for a process running

Posted on 2002-06-16
5
278 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:bhuvneshsharma
5 Comments
 
LVL 5

Accepted Solution

by:
ecw earned 30 total points
Comment Utility
ps -e | grep program > /dev/null || echo program not running | mailx -s "program not running" operator
0
 
LVL 5

Expert Comment

by:Nisus091197
Comment Utility
I have just the thing for you, I'll look for it and send the script.

Regards, Nisus
http://www.omnimodo.com
0
 

Expert Comment

by:marimba
Comment Utility
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.  
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
0
 

Expert Comment

by:SpideyMod
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now