- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- check me for a process and restarting if the proce...
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
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
тАО10-19-2004 09:45 AM
тАО10-19-2004 09:45 AM
I relatively new to the scripting world and would like a script that would go out and check a process and if it doesn't find it, the restart it. The process is called rclproc, any help would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 09:56 AM
тАО10-19-2004 09:56 AM
Re: check me for a process and restarting if the process is not found
there are many ways to do this
this example is one that will start a program that will run for ever and check ever 5 minutes to see if the program is running. If not it restarts the program.
#! /bin/sh
while true; do # infinite loop
var=$(ps -ef | grep -v grep | grep rclproc) # check to see if program is running
if [[ -z "$var" ]]; then
/usr/local/bin/rclproc > /dev/null 2>&1 & # run program if nothing is found inthe ps
else
var="" # reset the variable to null
fi
sleep 300 # sleep 5 minutes
done
you could always eliminate the infinate loop, and run it from cron ever 5 mintues or so
Hope this is helpfull
Sincerely
--Scott Palmer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 09:58 AM
тАО10-19-2004 09:58 AM
Re: check me for a process and restarting if the process is not found
create a script foo2 with the code snippet in it.
chmod 750 foo2
./foo2 > /dev/null 2>&1 & # run pipe output to /dev/null and background process.
or you could do
echo "./foo2" | at now
etc.
Sincerely
--Scott Palmer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 10:08 AM
тАО10-19-2004 10:08 AM
Re: check me for a process and restarting if the process is not found
You can try something like this
#!/usr/bin/sh
PROCNAME="rclproc"
while true
do
ps -ef | grep -q "$PROCNAME" >/dev/null 2>&1
if [[ $? -ne 0 ]]
then
# Process is not there
/path/to/the/procname
[ $? -eq 0 ] && echo "$PROCNAME successfully started"
fi
sleep 300
done
- Sundar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 10:18 AM
тАО10-19-2004 10:18 AM
SolutionThis script does little bit of checking. Modify the lines with appropriate details whereever I indicated them with # mark before running. It basically does the following
1. check if the process is running. If so, do nothing.
2. If the process is not running, then log a message in /tmp/rclproc.log file and start it. If it starts, then log a successful message into the log file.
3. If the startup was not successful, then send you a mail and creates file /tmp/rclproc.nocheck and will stop monitoring the process. Fix the errors, remove the stamp file and it will start monitoring it again.
Put it in 'cron' to run every 5 mins. Test it prior to implementing it.
#!/usr/bin/ksh
PROC="rclproc"
STARTCMD="your_command_to_start_rclproc" #<==modify
LOGFILE=/tmp/rclproc.log
EMAIL=your_mailid@yourdomain.com #<==Modify
STAMP=/tmp/rclproc.nocheck
touch $LOGFILE
check_pid()
{
MESG=$1
STATUS=$2
UNIX95= ps -C "$PROC" > /dev/null 2>&1
if [ $? != 0 ]
then
echo "$(date): $PROC $MESG" >> $LOGFILE
$STARTCMD
else
echo "$(date): $PROC has been successfully started" >> $LOGFILE
STATUS=0
fi
}
if [ ! -f $STAMP ]
then
check_pid "not running" 0
check_pid "is still not running" 1
if [ $STATUS = 1 ]
then
echo "Unable to start $PROC. Fix the errors
and remove $STAMP file to resume monitoring"| mailx -s "$PROC failure" $EMAIL
touch /tmp/envd.nocheck
fi
fi
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 01:23 PM
тАО10-19-2004 01:23 PM
Re: check me for a process and restarting if the process is not found
One of the options is "respawn" which will start a script at boot, and if it terminates, will relaunch it.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 03:05 AM
тАО10-20-2004 03:05 AM
Re: check me for a process and restarting if the process is not found
Thanks for the script but your script doesn't really just stops at checking for the process it goes out and restart it as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 03:11 AM
тАО10-20-2004 03:11 AM
Re: check me for a process and restarting if the process is not found
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 03:14 AM
тАО10-20-2004 03:14 AM
Re: check me for a process and restarting if the process is not found
Be sure to check out the answer here as well:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=199874
There might be some other alternatives as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 03:21 AM
тАО10-20-2004 03:21 AM
Re: check me for a process and restarting if the process is not found
"start_process" refers to starting the process. If it is being started from /sbin/init.d/rclproc, then the above command look like follows.
kill -0 $(ps -ef|grep [r]clproc|awk '{print $2}' || /sbin/init.d/rclproc start
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 03:24 AM
тАО10-20-2004 03:24 AM
Re: check me for a process and restarting if the process is not found
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:00 AM
тАО10-20-2004 04:00 AM
Re: check me for a process and restarting if the process is not found
I think you misunderstood me, I don't want it to restart the process, if the process is already running, if the process is still running then it should just sleep and if its not found then restart it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:08 AM
тАО10-20-2004 04:08 AM
Re: check me for a process and restarting if the process is not found
"I don't want it to restart the process, if the process is already running, if the process is still running then it should just sleep and if its not found then restart it. "
The above description is confusing for sure, atleast to me. :-)
- Sundar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:10 AM
тАО10-20-2004 04:10 AM
Re: check me for a process and restarting if the process is not found
Sri script is meant to be executed from cron. Schedule that script to run once in every N minutes via cron.
If you dont want to do that, you can use the script excerpt from my post, which uses an infinite loop with sleep command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:13 AM
тАО10-20-2004 04:13 AM
Re: check me for a process and restarting if the process is not found
I guess I know what you meant. It doesn't really restart the process but it only displays the message. Replace the function check_pid like this
check_pid()
{
MESG=$1
STATUS=$2
UNIX95= ps -C "$PROC" > /dev/null 2>&1
if [ $? != 0 ]
then
echo "$(date): $PROC $MESG" >> $LOGFILE
$STARTCMD
else
STATUS=0
fi
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:40 AM
тАО10-20-2004 04:40 AM
Re: check me for a process and restarting if the process is not found
Thanks for your help. I got it now. :)
De
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2004 04:44 AM
тАО10-20-2004 04:44 AM