![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Check for statup process in loop? | dataciph3r | Shell Programming and Scripting | 1 | 09-25-2008 09:18 PM |
| Check whether ftpd process is running or not? | The.White.Rider | SUN Solaris | 8 | 06-17-2008 07:51 AM |
| check process running | rose1207 | Shell Programming and Scripting | 4 | 12-28-2007 01:23 AM |
| Infinite Loop in Autosys while running a shell script, Manual run is fine | sharmagaurav_2k | Shell Programming and Scripting | 2 | 09-04-2007 08:20 AM |
| How to check if another instance of the process is running | sim | Shell Programming and Scripting | 8 | 06-30-2005 07:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
infinite loop to check process is running
Hi,
I got a simple script working to check if a process is running and then email if it is not running anymore. My scenario is that I need to make sure the process is always running so instead of running the below script via cron I think it is better to a have a looping script to check continually. I'm unsure on this and don't want to bodge it up and create a burden to the system. I did search but couldn't get a match that helped me. Can anyone point me at a sample I can edit please? Cheers Code:
#!/bin/csh
# This script checks to see if process e_1 is up, if down it sends an email. If up it exits.
#
set DATE=`date +%d%m%y`
set TIME=`date +%H%M`
set RECIPIENT="email@"
set DPID = `ps -ef | grep -v grep | grep e_1`
if ("$DPID" == "") then
echo "The e_1 process went down at $TIME on $DATE" | mail -s "The u_1 process went down" $RECIPIENT
else
echo "e_1 is up"
endif
exit
|
|
||||
|
hi jim.
thanks for your reply. would a better model be? a loop to check a process is ruuning, if it is then no action, if it isn't then start the process and at that point send an email to say that it has been re-started. then go back to start of the loop. cheers mark |
|
||||
|
Yes, if it can
restart and check the process 3 times before sending an email 'Process wont run' Put a sleep command in there at the bottom of the loop Code:
failure_count=0;
while true
do
# your code here
# end of your code
if [[ $failure_count -gt 2 ]] ; then
echo "Can't run process X" |\
/usr/bin/mailx -s 'Process X failed' me@myaddress.com mybackup@hisaddress.com
failure_count=0
fi
sleep 10
done
|
|
||||
|
thanks for your help. i'm writing this in csh as i have to use a source command to be able to start a process within a certain environment. all the other scripts on the server are also csh so i'm not sure if I can change to sh or kcsh.
I'm not really a scripter so am a bit unsure how to get the failure count to work. i have tried both of these but they just get stuck on the expression is true part. sorry for being dumb. this one is checking DPID to see if it IS NOT empty. Code:
set DPID = `ps -ef | grep -v grep | grep e_1`
set FAILURE_COUNT="0"
while ("$DPID" != "")
echo "e_1 is up"
if ("$FAILURE_COUNT" > "2") then
echo "test"
failure_count=0
endif
sleep 10
end
this one is checking DPID to see if it IS empty. Code:
set DPID = `ps -ef | grep -v grep | grep e_1`
while ("$DPID" != "")
echo "e_1 is up"
if ("$DPID" == "") then
echo " test"
endif
sleep 10
end
|
|
||||
|
hi danmero,
i was using using the grep below as it only returns something if it finds it. Code:
ps -ef | grep -v grep | grep e_1 Code:
ps -ef | grep "ue_21" |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|