Trigger a script when nohup process terminates

443 views Asked by At

I have some fairly time consuming python scripts to run ~3 hours or so on my machine. I don't want to run them concurrently since it might crash my machine. Alone I have more than enough memory but running 5 or so might cause an issue. I am running them remotely so I ssh into my server and run them like this:

nohup python my_script.py > my_output.txt &

That way if my connection gets interrupted I can re-establish the connection and my result is right there. I want to run the same python script a couple times with different command line arguments sequentially so I can run everything I need without me needing to set up the next one every few hours. I could manually code all of the arguments into a python script and do it that way but it seems inelegant. I don't want to have to fiddle with my python script every time I do this. Is there some sort of listener I could use to trigger the next one when one of them finishes?

2

There are 2 answers

1
Tom McDermott On BEST ANSWER

I'd suggest writing a bash script that runs the python jobs sequentially:

#!/bin/bash

python3 my_script1.py > my_output1.txt
python3 my_script2.py > my_output2.txt

Then nohup that:

nohup ./driver.sh &
1
AudioBubble On

You really want to read up on utilities like tmux or screen and just script the while thing.