Running multiple python scripts sequentially with nohup

requests=(25 50 75 100)
factors=(3 6)
graphsizes=(25 50 75)

for request in "${requests[@]}" 
  for factor in "${factors[@]}"
    for size in "${graphsizes[@]}"
        echo "Now Running: n = ${request}, factor = ${factor}, size = ${size}" >> nohup.out
        nohup python3 -u "$request" 50 "$factor" "$size" > ${request}_${factor}_${size}.log 
        echo "Done Running: n = ${request}, factor = ${factor}, size = ${size}" >> nohup.out

My intention: I want to run all the various permutation of arguments to sequentially; i.e., print Now Running..., then call nohup and run the python script, when that is done print Done running...

Note that I cannot add a & at the end of the nohup line, since that would make the script proceed before has finished.

However, by not using the &, I can no longer use the current shell process while this script is running. Is there any way to get around this?

>Solution :

What you probably want, is the following: remove the nohup from the commands in your shell script, but run the overarching script that you show here (i.e., all the code; let’s call it iterations.bash with nohup and in the background: nohup bash iterations.bash >& iterations.log &. Now you have your command line back, while the processes inside the script are run sequentially.

Leave a Reply