- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- shell script for tracking processes
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 11:10 AM
тАО01-29-2006 11:10 AM
We are running an application on hpux11i and it runs 2 processes.
I want to know the shell script which can send me an email if the processes are stopped running.
I am not a seasoned shell scriptor, so your help is appriable.
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 11:59 AM
тАО01-29-2006 11:59 AM
SolutionYou could create a 'cron' task for the following. Assume that you want to look for a process called "myproc" and email/page if it isn't running:
# [ -z "`UNIX95= ps -C myproc -o pid= -o comm=`" ] && mailx -s "myproc" is not running!" root < /dev/null
You could replicate this for you second process too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 03:41 PM
тАО01-29-2006 03:41 PM
Re: shell script for tracking processes
for critical processes, you can also include the coding for the processes to restart also.
of course, you should identified all possible scenarios that can cause your processes to stop..
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 03:52 PM
тАО01-29-2006 03:52 PM
Re: shell script for tracking processes
You can just use ps -ae |grep -i "process_name" and if [ $? >0 ] mailx -s "Process_name not running"
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 05:01 PM
тАО01-29-2006 05:01 PM
Re: shell script for tracking processes
One time:
ps -ef | grep -i
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-29-2006 05:03 PM
тАО01-29-2006 05:03 PM
Re: shell script for tracking processes
#!/bin/ksh
PROCESS_NAME=
SLEEP_TIME=60 # 1 minute
while [[ 1 ]]
do
ps -ef | grep -qi "${PROCESS_NAME}" | mailx -s "Process @ $(date)" ID
sleep ${SLEEP_TIME}
done
# END
exit 0
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2006 08:24 PM
тАО01-30-2006 08:24 PM
Re: shell script for tracking processes
something like this
PROCESS_COUNT=$(ps -fu <script user> | grep <script_name> | grep -v grep)
case $PROCESS_COUNT in
0) TITLE=
echo "ERR: <script_name is not running"|mailx -s $TITLE
;;
1) #OK
;;
*) TITLE=
echo "ERR: more than 1 process is running"|mailx -s $TITLE
;;
esac
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2006 12:08 AM
тАО01-31-2006 12:08 AM
Re: shell script for tracking processes
However, all scripts that monitor the system to provide notifications will cause big email problems if they do not stop or slow down once the notification has been sent. You can put James' 1-liner into a loop that runs until a notification is made:
#!/usr/bin/sh
set -u
export PATH=/usr/bin
# $1 is the process to monitor
if [ $# -lt 1 ]
then
echo "need MYPROC"
exit 1
fi
MYPROC=$1
SYSADM=root # replace root with another email addr
MONSECS=30
RETRYSECS=3600
while :
do
MYSTATUS="$(UNIX95= $MYPROC -o pid= -o comm=)"
if [ -z "$MYPROC" ]
then
mailx -s "$MYPROC is not running!" $SYSADM
sleep $RETRYSECS
fi
sleep $MONSECS
done
Now start the script in the background and it will run forever, but will provide the email warning once (within 30 seconds) of the failure, and then repeat the message every hour until the process is fixed.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2006 12:11 AM
тАО01-31-2006 12:11 AM
Re: shell script for tracking processes
MYSTATUS="$(UNIX95= ps -C $MYPROC -o pid= -o comm=)"
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2006 12:49 AM
тАО02-06-2006 12:49 AM
Re: shell script for tracking processes
I am also interesting in this. But i find that $MYSTATUS is always null.
What might i be doing wrong?
I presume the script is supposed to be "-z $MYSTATUS" rather than $MYPROC.
I am aware of UNIX95 but ps -C.... is always null... :-(
this would be most useful!