Solved

Checking for a process running

Posted on 2002-06-16
5
284 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
ID: 7082224
ps -e | grep program > /dev/null || echo program not running | mailx -s "program not running" operator
0
 
LVL 5

Expert Comment

by:Nisus091197
ID: 7090986
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
ID: 7268539
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
ID: 8003339
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
ID: 8065831
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

828 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