Solved

Checking for a process running

Posted on 2002-06-16
5
283 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sudo logging 5 93
cron job says it ran, no results 25 118
How to check files recursively from multiple directories and get latest file in bash script 6 99
UNIX SCP 5 77
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.

777 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