Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux bash script running multiple python

Tags:

python

linux

bash

I have 2 python scripts a.py and b.py and I want to write a bash script that will load a.py and not run b.py until a.py is done doing it's thing. simplistically

#!/usr/bin/env bash
python a.py
python b.py

but this is naive, a check to see if a.py is done... how do I do that?

like image 548
StudentOfScience Avatar asked Dec 03 '12 22:12

StudentOfScience


People also ask

What is %% bash in Python?

%%bash. Means, that the following code will be executed by bash. In bash $() means it will return with the result of the commands inside the parentheses, in this case the commands are: gcloud config list project --format "value(core.project)" Google cloud has its own command set to control your projects.


1 Answers

This by default will already run one after the other.


To check that python a.py completed successfully as a required condition for running python b.py, you can do:

#!/usr/bin/env bash
python a.py && python b.py

Conversely, attempt to run python a.py, and ONLY run 'python b.py' if python a.py did not terminate successfully:

#!/usr/bin/env bash
python a.py || python b.py

To run them at the same time as background processes:

#!/usr/bin/env bash
python a.py &
python b.py &

(Responding to comment) - You can chain this for several commands in a row, for example:

python a.py && python b.py && python c.py && python d.py 
like image 197
sampson-chen Avatar answered Oct 17 '22 01:10

sampson-chen