How can I automatically start a script after two scripts that worked together are finished?

Viewed 30

I actually run two python scripts with a shell command, but when they finish how can automatically run the third?

Do you know a procedure that can I add in the same .sh to do that?

For the .sh file I use:

python script1.py && python script2.py

I want to run a script3.py after this sequence. Someone can help me?

(obviously I run the script on terminal with

>chmod u+x shell.sh   
>./shell.sh                                   

      

Best regards.

1 Answers

This will execute each subsequent script only if all the preceding ones succeeded, that is, if all of them exited with status = 0. Remember to add && between the scripts:

python script1.py && python script2.py && python script3.py

Example:

All 3 scripts are executed:

$ python -c 'print(1); exit(0);' && python -c 'print(2); exit(0);' && python -c 'print(3); exit(0);'
1
2
3

Only the first 2 scripts are executed:

$ python -c 'print(1); exit(0);' && python -c 'print(2); exit(1);' && python -c 'print(3); exit(0);'
1
2

Related