botieeee
botieeee

Reputation: 1

bash repeat python scripts until succeed

I am trying to figure out how to use bash to run four python scripts in parallel and when one of them failed, keep running that one until it succeeds. The code I have right now is

while ./test0.py; do :; done &
while ./test1.py ; do :; done &
while ./test2.py ; do :; done &
while ./test3.py ; do :; done

However, this seems like keep running until one of them fails.

Is there anyway to achieve keep running the one that's failed until it succeeds? (I have made them executable, so I did directly ./ )

Upvotes: 0

Views: 537

Answers (2)

JRajkumar
JRajkumar

Reputation: 1

A slight variation to the previous answer, we can make the bash script sleep for a while, if we need to wait before testing the completion of the Python code.

while ./test.py ; do:; sleep 5m; done

The above command checks, if test.py has completed its execution. If not, it keeps checking every 5 mins until we get a sys.exit(0) from the Python code

Upvotes: 0

Barmar
Barmar

Reputation: 781350

Use until to invert the test.

until ./test0.py; do :; done &
until ./test1.py; do :; done &
until ./test2.py; do :; done &
until ./test3.py; do :; done

Upvotes: 2

Related Questions