Running multiple python scripts sequentially with nohup

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

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

My intention: I want to run all the various permutation of arguments to main.py 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 main.py 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