user5505266
user5505266

Reputation: 603

Trigger a script when nohup process terminates

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?

Upvotes: 2

Views: 484

Answers (2)

Tom McDermott
Tom McDermott

Reputation: 221

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 &

Upvotes: 2

user4822941
user4822941

Reputation:

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

Upvotes: 0

Related Questions