Computing.Net > Forums > Unix > shell script (polling)

shell script (polling)

Reply to Message Icon

Original Message
Name: Mehul
Date: October 29, 2002 at 16:26:50 Pacific
Subject: shell script (polling)
OS: Sun solaris
CPU/Ram: sun5.8
Comment:

Hi
I would like to know if i can do polling in shell script ..basically i want to wait till certain task1 is completed than only start task2....can i do this in shell script

aprreciate ur help...Thx in advance


Report Offensive Message For Removal


Response Number 1
Name: Don Arnett
Date: October 29, 2002 at 18:25:51 Pacific
Reply: (edit)

I'm not sure that a shell script is the way to do this, or at least there may be better options. How will you determine that task1 is done? How often do you want to check?


Report Offensive Follow Up For Removal

Response Number 2
Name: jimbo
Date: October 29, 2002 at 22:09:22 Pacific
Reply: (edit)

If you are starting both tasks in the script,
you can run task 1 in the background like this:

task_1 &

The $! variable holds the Process ID of the last backgrounded process. Thus if you used this and the wait command, task 2 would not start until task 1 completes. example:

task_1 &
wait $!
echo "Task 1 finished, starting task 2"
task_2

If task 1 is already running and you want to start task 2 when it completes, do something like this (adjust the sleep time as needed):

#! /bin/ksh
while : ; do
if pgrep TASK_1_NAME ; then
:
else
Start_task_2_here
break
fi
sleep 30
done
print "Task 2 started at `date`"


Hope this helped.
-jim


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: shell script (polling)

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge