8

I have two scripts say 'S1' and 'S2'. I execute these scripts as,

nohup S1 &

nohup S2 &

But I would like them to execute sequentially. ie., S2 should execute only on successful completion of S1. How should I go about doing this?. How can I know when S1 finishes execution?. Any examples would be much appreciated. Thanks.

wowrt
  • 737
  • 2
  • 8
  • 9

1 Answers1

13

You can execute them, sequentially, like this:

(nohup S1 && nohup S2) &

Try

(echo 1 && sleep 1 && echo 2) &

The double ampersand operator is described here.

Note that when using &&, S2 only runs if S1 finishes "successfully" (return code 0). This seems to be what you wanted. If you want S2 to run regardless of whether S1 succeeds, use ; instead of &&.

Stephen
  • 47,994
  • 7
  • 61
  • 70
  • hi, stephen! Would you please help me with this question http://unix.stackexchange.com/questions/101411/how-to-run-new-background-command-sequentially-if-i-already-have-a-nohup-backgro/101421?noredirect=1#comment154602_101421 ? I will be very appreciate. – user15964 Nov 17 '13 at 02:51