Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 4672  / 1 Year ago, sun, december 11, 2022, 8:23:02

I have a python program which, from time to time, crashes with a number of different exceptions usually due to network issues. The only way to get it to work is to restart it. How would I write a shell script to run the process, continually check if any of the output says Error and if so end the process and restart the command (let's call it ./command.sh)?



It would be fine for this to be in any other language (python/perl etc).


More From » bash

 Answers
3

Since python exits with an return code != 0 when it throws an exception, you can just run this shell script:



while ! ./command.sh ; do : ; done


Of course if you just want to run the command all the time, just write:



while true ; do ./command.sh ; done


(this assumes ./command.sh doesn't fork and exit)


[#44623] Monday, December 12, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
confiorc

Total Points: 42
Total Questions: 121
Total Answers: 123

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
;