It is currently Tue, 17 May 2022 01:20:46 GMT



 
Author Message
 Command to wait for previous process/command to finish
Hi there

I am a newbie to unix scripting
Was wondering whether anyone can help me here.. WHat i want to do is...

run { system_command_1, get process_id_1}

when {system_command_1 finishes}{
        run system_command_2, get process_id 2        

when {system_command2 finishes}{
        run system_command_3, get process_id 3  
......

and it goes on and on and on...

Anyone?

Thanks

Redza



 Fri, 02 Apr 2004 18:52:15 GMT   
 Command to wait for previous process/command to finish
On 15 Oct 2001 03:52:15 -0700, in article
<79c1319c.0110150252.3da6...@posting.google.com>, r...@e{*filter*}.com (Rashyid)
wrote:

man wait
--
gburnore at DataBasix dot Com
---------------------------------------------------------------------------
                    Are you going to Scarborough Fair?
---------------------------------------------------------------------------
Gary L. Burnore                       |  Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3
                                      |  Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3
Official .sig, Accept no substitutes. |  Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3
                                      |  Y? 0 1 7 2 3 / Y3T 3 7 4 9 3 0 ?3
Black Helicopter Repair Services, Ltd.|     Official Proof of Purchase
===========================================================================



 Fri, 02 Apr 2004 19:05:52 GMT   
 Command to wait for previous process/command to finish
Well, that's what will happen by default when you run a set of
commands.  But I'll assume that you want to be able to do something a
little bit fancier.

So:

################################################
# Execute command_1 in the background.
# Get its PID.
# Run some other commands.
# Then wait for command_1 to finish.
command_1 &
PID_1=$!

run_other_command
run_other_command
do_something_else

wait $PID_1

################################################
# Now that command_1 has finished....
# Execute command_2 in the background.
# Get its PID.
# Run some other commands.
# Then wait for command_2 to finish.
command_2 &
PID_2=$!

run_other_command
run_other_command
do_something_else

wait $PID_2

################################################
# etc...



 Fri, 02 Apr 2004 21:51:40 GMT   
 Command to wait for previous process/command to finish

for bourne/korn varients there is the "wait" command; e.g.:

command
wait
command
wait

HTH
---
mark



 Fri, 02 Apr 2004 21:56:49 GMT   
 Command to wait for previous process/command to finish
Hi again..

Thanks for your replies.. actually what i really need to know is if
something like the below can be done..

run command_1
      |
    wait til it finishes ---> run command_2 --> wait --> run command_6
      |
      V
run command_3
      |
      V
    wait til it finishes ---> run command_4 ---> wait --> run
command_7
      |
      V
run command_5
     |
.... etc etc

as you can see.. i need it such that after command 1 is run, command 2
and 3 waits til its finished before they start.. and then, the same
would happen at command 3 where 4 and 5 will wait til it finishes
before it runs.. If it was a 'straight line' relation, it would be ok,
but the thing i am not too sure is when 2 different commands wait for
a particular command before they are run

Thanks again for your responses..

Rashyid



 Sat, 03 Apr 2004 09:09:26 GMT   
 Command to wait for previous process/command to finish

if I understand you correctly this might do it, using subprocesses:

command_1
(command_2
command_6)&
command_3
(command_4
command_7)&

and so on....

here is a simple ksh demo:
oscar$print 1 ; (sleep 5 ; print 2)&  print 3
1
[1]     25964
3
oscar$2

[1] +  Done                    print 1 ; (sleep 5 ; print 2)&  print 3
oscar$

marc

ps this structure is recursive, you can build it as deep as you want

marc



 Sat, 03 Apr 2004 12:11:03 GMT   
 
   [ 6 post ] 

Similar Threads

1. ksh script - waiting previous command line

2. how do i wait for child processes, and *their* children to finish

3. waiting for child process to finish

4. Bleep when process finished / idle / waiting for input

5. Wait for process to finish

6. how to wait for a process to finish

7. Waiting for multiple background processes to finish

8. sh: wait til process finishes?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software