loop when process running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop when process running
# 1  
Old 04-28-2009
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 easySmilie)

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 commands and then stop.
# 2  
Old 04-28-2009
Quote:
Originally Posted by blackwire
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 easySmilie)

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 commands and then stop.

Hello,

Please go through the crontab basics, give it a try first and please explain as much as you can in the post. Check out the link below.

Unix Crontab - setting up cron jobs using crontab

Many thanks
# 3  
Old 04-29-2009
as i said crontab will be easy... I am having problems with the shell script loop
# 4  
Old 04-29-2009
You can have a script which is fired at 2400 hrs , the Pesudocode for that script is as below

If you provide me details then I can write a script.

while [ grep(ing) for the process you want.]
do
if that process is not found
then
do the necessary steps you wish to do
else
sleep 30
fi
done

Cheers
Sachin Raje.
# 5  
Old 04-29-2009
ok. i m now up with this solution.
----------------
#!/bin/csh
while (`ps -ef | grep -c "[P]opChar"` == "1")
echo "PopChar is up"
sleep 30
if (`ps -ef | grep -c "[P]opChar"` == "0") then
echo "The PopChar utility not running"
endif
end
----------------

the problem I have now is that the part

echo "The PopChar utility not running"

not will be not will be executed if the script starts
and PopChar isn't running. how can i establish this functionality
# 6  
Old 04-29-2009
How long to you wish to keep on looking for the PopChar utility if it is not found ?
That answer will be your and conditon in the while loop to break and exit.
Hope that helps.

cheers
Sachin Raje.
# 7  
Old 04-29-2009
Try this - not tested

Code:
#!/usr/bin/sh
echo "start"
if [ `ps -ef | grep -c "sleep"` -gt 0 ];
then
flag=true
else
echo "POPchar is down"
echo "Exiting now"
flag=false
fi
while [ "$flag" = "true" ]
do
if [ `ps -ef | grep -c "sleep"` -gt 0 ]; then
echo "POPChar is running"
flag=true
sleep 30
else
echo "POPchar is down"
flag=false
fi
done

cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

6. 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

7. Shell Programming and Scripting

perl process loop isn't running

I'm trying to figure out why the perl process we have running in a loop isn't working. Basically its setup to read our queue from Amazon SQS with the results getting inserted into the db. We are using EC2 for video transcoding and once the conversion takes place our web server hosted outside... (10 Replies)
Discussion started by: kwick6
10 Replies

8. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

9. Shell Programming and Scripting

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... (12 Replies)
Discussion started by: yabai
12 Replies

10. UNIX for Advanced & Expert Users

How to create a dummy process of a process already running?

Hi Everybody, I want to create a shell script named as say "jip" and it is runned. And i want that when i do ps + grep for the process than this jip should be shown as process. Infact there might be process with name jip which is already running. (3 Replies)
Discussion started by: shambhu
3 Replies
Login or Register to Ask a Question