loop when process running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop when process running
# 8  
Old 04-29-2009
lets run thru the logic here for better clarity and blackwires benefit
cronjob script "x" kicked off @midnight which does all the good stuff.

There 3 possibilities

1. PopChar has already finished. ( is there a log with a specific date which can be read ? )
2. currently running ( script X takes careof this situation )
3. did not start yet ( look for the log with a specific date exits )

waiting on your input Blackwire,

Cheers,
Sachin Raje.
# 9  
Old 04-30-2009
hi Devaraj,
if i now start the script and the process PopChar isn't running i immediately get the message

start
POPChar is running
Smilie
it den cycles through the loop POPChar is running

if i start the script and the process PopChar is running it cycles through the loop POPChar is running, that's ok. but if i then stop the process it still cycles
through POPChar is running Smilie

Many thanks
# 10  
Old 04-30-2009
Quote:
Originally Posted by blackwire
hi Devaraj,
if i now start the script and the process PopChar isn't running i immediately get the message

start
POPChar is running
Smilie
it den cycles through the loop POPChar is running

if i start the script and the process PopChar is running it cycles through the loop POPChar is running, that's ok. but if i then stop the process it still cycles
through POPChar is running Smilie

Many thanks
Did you grep the right string. I pasted the code as an example

you will need to grep your process name

Code:
if [ `ps -ef | grep -c "sleep"` -gt 0 ]; then

cheers,
Devaraj Takhellambam
# 11  
Old 05-04-2009
hi Devaraj,

yes i changed the process name to PopChar but i still have the same behavior i told you bevor

if i start the script and the process PopChar isn't running i immediately get the message

start
POPChar is running

it den cycles through the loop POPChar is running

if i start the script and the process PopChar is running it cycles through the loop POPChar is running, that's ok. but if i then stop the process it still cycles through POPChar is running.

------------
#!/bin/sh
echo "start"
if [ `ps -ef | grep -c "PopChar"` -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 "PopChar"` -gt 0 ]; then
echo "POPChar is running"
flag=true
sleep 5
# 12  
Old 05-04-2009
Quote:
Originally Posted by jville
lets run thru the logic here for better clarity and blackwires benefit
cronjob script "x" kicked off @midnight which does all the good stuff.

There 3 possibilities

1. PopChar has already finished. ( is there a log with a specific date which can be read ? )
2. currently running ( script X takes careof this situation )
3. did not start yet ( look for the log with a specific date exits )

waiting on your input Blackwire,

Cheers,
Sachin Raje.
hi Sachin,

the logic is (hope you understand what i mean Smilie )

a cron job starts a shell script (say "X") once every 24 hours

script "X" takes careof

is process PopChar running ?

if no --> execute shell command x,y,z (the same as below)
then exit

if yes --> loop and test process PopChar until it isn't running
then execute shell command x,y,z (the same as above)
then exit

Many thanks
# 13  
Old 05-05-2009
now it works,
this is the solution.

#!/bin/sh
#
echo "start"
DATE=`date`
#
if [ `ps -ef | grep -c "[P]opChar"` == "1" ];
then
flag=true
else
echo "POPchar is down"
echo "Exiting now"
flag=false
fi
while [ "$flag" = "true" ]
do
if [ `ps -ef | grep -c "[P]opChar"` == "1" ]; then
echo "POPChar is running"
flag=true
sleep 5
else
echo "the POPchar process went down at $DATE"
flag=false
fi
done

Many thanks for your support
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