infinite loop to check process is running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting infinite loop to check process is running
# 8  
Old 10-20-2008
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

The grep below returns the process if it is running as well as the process of grep itself. Therefore this grep will always return something so I can't test if it IS NOT empty.
Code:
ps -ef | grep "ue_21"

When using a simple if statement my grep does work. sorry if i am missing something.
# 9  
Old 10-20-2008
Quote:
Originally Posted by yabai
The grep below returns the process if it is running as well as the process of grep itself. Therefore this grep will always return something so I can't test if it IS NOT empty.
Code:
ps -ef | grep "ue_21"

When using a simple if statement my grep does work. sorry if i am missing something.
Yes, use the brackets.
Code:
ps -ef | grep "[u]e_21"

# 10  
Old 10-22-2008
Hi, thanks for the feedback. I did note the [] brackets in th grep. Here is what I have now.

When I run this it loops but keeps echoing ue_21 is up even when i stop the ue_21 process. I am checking that it isn't re-starting it as well. The script doesn't get to the echo " test" part. Sorry if this is obvious but I am really scratching my head at this as it looks correct. cheers if anyone has any ideas as to where i am going wrong.

Code:
set DATE=`date +%d%m%y`
set TIME=`date +%H%M`
set RECIPIENT="test@test.co.uk"
set DPID = `ps -ef | grep "[u]e_21"`

while ("$DPID" != "")
     echo "ue_21 is up"
if ($DPID == "") then
     echo " test"
     echo "The ue_21 utility went down at $TIME on $DATE" and was told to restart | mail -s "The ue_2
1 utility went down" $RECIPIENT
endif
sleep 10
end

# 11  
Old 10-23-2008
Quote:
Originally Posted by yabai
Code:
set DPID = `ps -ef | grep "[u]e_21"`

You have space char's around equal =
# 12  
Old 10-23-2008
hi again. i'm afraid it still doesn't work. I'm thinking it is because it should be;

while (true)

whereas i am doing;

while (not true)
while ("$DPID" != "")

I've done further tests to try and get the expression to work and think it must be to do with the operators.

effectively i need to say whil DPID IS SOMETHING

i have just tried this but it doesn't echo the text in the while script so is not working;
while ("$DPID" =~ "*")

Cheers if anyone can take a look.
# 13  
Old 10-23-2008
i made some changes and it appears to be working now so it may be of help to someone out there;
#!/bin/csh
set DATE=`date +%d%m%y`
set TIME=`date +%H%M`
set RECIPIENT="test@test.co.uk"

while (`ps -ef | grep -c "[u]e_21"` == "1")
echo "ue_21 is up"
sleep 10
if (`ps -ef | grep -c "[u]e_21"` == "0") then
echo "The ue_21 utility went down at $TIME on $DATE" and was told to restart | mail -s "The ue_21 utility went down" $RECIPIENT
endif
end
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select command going to infinite loop after running the script

cd /opt/et/WAS/apps/8.0 find . -name "HostIntegration.properties" -o -name "HostSocket.properties" -o -name "environment.properties" 2> /dev/null | awk -F '' '{print $4}'|awk '!x++' | cat>/home/cbadmin/file1.txt cd /home/cbadmin/ PS3='Please enter a number from list of applications==>:' select... (3 Replies)
Discussion started by: bhas85
3 Replies

2. Shell Programming and Scripting

Infinite while loop script shows more than one process

Hi, I have a script which triggers an infinite loop. #!bin/bash trig=`ls /home/trig.tch |wc -l` function callj { some commands... } while do callj & done The number of process after doing a ps -ef |grep Mon.sh returns processes even after the script is killed by deleting the... (4 Replies)
Discussion started by: chetan.c
4 Replies

3. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

4. Shell Programming and Scripting

need to check if the process is running

Hi, I check if the process is running or not using the below. /usr/ucb/ps auxww | grep 109 |grep rmi | awk '{print $2}' 9718 Thus we see 9718 is the PID. It return blank if the process is not running. I need to perform some action if the process is not running and leave it if... (8 Replies)
Discussion started by: shifahim
8 Replies

5. Programming

How do I check if a process is running in C

How to I check if a process is running in C? I'm trying to use ps aux |grep "process name" but failing in doing that. How do I do that? Thanks, (1 Reply)
Discussion started by: cprogdude
1 Replies

6. UNIX and Linux Applications

How to check if process is running?

Hi I would like to check if an instance of a script is already running. I've seen many different examples, but I haven't the slightest idea as to how to do this. Can you please help. Thank you. (5 Replies)
Discussion started by: ladyAnne
5 Replies

7. Shell Programming and Scripting

Check if Process is running

Hi , I have a csh code below which check the process if it's running. Can any expert advise me on the following: 1) what does this notationmean ">!" and how is it different from the append ">" notation ? 2) how does "setenv" work in this code ? # Check whether there is a running... (3 Replies)
Discussion started by: Raynon
3 Replies

8. Shell Programming and Scripting

loop when process running

Hi Gurus, Could you please help me to create a shell script that will be started by a cron job once every night at 24.00 h (that should bee easy:)) The shell script should control every 30 seconds the name of a process, and when the process doesn't run anymore it should execute a few further... (12 Replies)
Discussion started by: blackwire
12 Replies

9. Shell Programming and Scripting

Running a script in INFINITE LOOP

Hi All, I have a requirement as below. I supposed to get a file from Source system once in a month. But we dont know when the source system will send the file. My script has to wait for that file in LOOP once it gets the file then it has to FTP the file. I thought of scheduling the job... (5 Replies)
Discussion started by: Raamc
5 Replies

10. Shell Programming and Scripting

check process running

I have this script: ------------------------------------------------------- #!/bin/ksh # if ] || ] then echo "Executing main_load.sh script" /usr1/psc_load/jobs/cron/main_load.sh "ods" else echo "File not found, do nothing" fi exit 0 ... (4 Replies)
Discussion started by: rose1207
4 Replies
Login or Register to Ask a Question