6

I have to run several python scripts one after another but want to make sure previous one got completed. How can I do that in Linux?

Can it be done by simply using && or ; or | ?

guntbert
  • 1,637
Sam
  • 71
  • 1
  • 2
  • 3

1 Answers1

10
  • With ; between the commands, they would run as if you've given the commands, one after the other, on the command line. A script would not start until the one before had finished. This would be the same as using a newline character between each command, specifying them on separate lines.

  • With &&, you get the same effect, but a script would not run if any previous script exited with a non-zero exit status (indicating a failure).

  • With ||, you get the same effect, but a script would only run if all the previous previous script exited with a non-zero exit status (indicating a failure).

  • With &, all scripts would run pretty much at the same time, concurrently, as asynchronous jobs (background jobs). This is unlikely what you want.

  • With |, all scripts would run pretty much at the same time, concurrently. The standard output stream of one script would be connected to the standard input stream of the next script in the pipeline. This is unlikely what you want.

Depending on what you mean by "got completed", you would probably want to use either ; (don't care about the exit status of the previous script) or && (care about the exit status; only run the script if the previous didn't signal a failure) between the commands.

Kusalananda
  • 333,661
  • By completed I meant script fished its task. Do we have to specify zero status in python code itself or if script finishes properly it would be considered as exit status? – Sam Nov 17 '19 at 22:33
  • @Sam If you just want to run one script after the other, without caring for the previous scripts exit-status (which will be zero most of the time, signalling "success", unless an explicit non-zero exit-status is given to sys.exit() or exit() in Python), then just run the scripts with ; between them. – Kusalananda Nov 17 '19 at 22:41