Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checking for a process running

Posted on 2002-06-16
5
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Accepted Solution

by:
ecw earned 120 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 21

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

730 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