- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script-Check if process running, if not start ...
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
Forums
Discussions
Discussions
Forums
Discussions
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
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
02-06-2001 04:26 AM
02-06-2001 04:26 AM
thanks,
Greg
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 04:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 04:48 AM
02-06-2001 04:48 AM
Re: Script-Check if process running, if not start it up
Use ps -e instead of ps -ef and
grep ' proc_name$'.
So
if [ $(ps -e | grep ' proc_name$' | wc -l) -ne 0 ]
then
exit # process run
fi
regards, Saa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 06:26 AM
02-06-2001 06:26 AM
Re: Script-Check if process running, if not start it up
Here's a hypothetical script that monitors a process that it spawns, restarting the process as soon as it dies. It gives you another example to think about:
#!/usr/bin/sh
function WHAT
{
sleep 30 & #...run in background...
}
while true #...forever...
do
WHAT
WHO=$!
echo "pid_${WHO} started"
while true
do
kill -0 $WHO 2> /dev/null #...check for the pid...
if [ $? -ne 0 ]
then
echo "\npid_${WHO} died"
break #...exit inner loop ...
else #...it's still alive...
sleep 1
echo ".\c"
fi
done
done
#_end
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 07:47 AM
02-06-2001 07:47 AM
Re: Script-Check if process running, if not start it up
Why reinvent the wheel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2001 07:01 PM
02-06-2001 07:01 PM
Re: Script-Check if process running, if not start it up
If you are involving the use of grep on a ps output, please remember to add a "| grep -v grep".
This is because grep itself is a process displayed with ps. If you ps -fae|grep PROC_NAME, other than the PROC_NAME process being reflected, "grep PROC_NAME" process will also be reflected. By adding "| grep -v grep" to form a "ps -fae|grep PROC_NAME|grep -v grep", you effectively filter off the display of the grep process.
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com