I am trying to write a bash script which launches an external python script, with some conditions.
The goal is to avoid waiting for the python script to complete, but wait a delay (eg. 30 seconds) and send the process to background if the python script is still running.
Very simplified python script example:
#!/usr/bin/python
import time
time.sleep(120)
In this case, I would like the bash script to launch the python script, wait for 30 seconds, and send the python process to background (like nohup example.py &
would do).
In case the python script would crash during the 30 seconds delay, the error message should display on terminal.
I cannot modify the python script.
Is it possible to do it in a clean way?
I managed to do the job by using nohup / &
and redirecting output of the python script to a temp file, and read this file after 30 seconds, to check if there is no error message.
But I am curious to know if there is a better way.
Thanks!