Friday, October 29, 2021

[SOLVED] How to trigger multiple nohup scripts at once?

Issue

I'm working on optimizing some of my workflow and was wondering if anyone has run into a similar issue as mine. I've been struggling to figure out how to start multiple "nohup" shell scripts at the same time. For example, I have several scripts that look like this:

start.sh

rm nohup.out
nohup python -u script.py args

I've tried running them with a script like this:

start_option_1.sh

process_directory_1/start.sh & process_directory_2/start.sh ... (3-5 more of these)

And like this:

start_option_2.sh

process_directory_1/start.sh && process_directory_2/start.sh ... (3-5 more of these)

but no dice... the scripts won't even start. Any ideas/help would be greatly appreciated!! Using python3.6 if that's important too (but seems like it's more of a nohup issue).


Solution

There is a big difference between using '&' and using '&&'. The first will run each of the scripts in the background. The second will executed them in sequence, as long as each scripts will return success ('exit 0', or equivalent).

From the context of 'start.sh', looks like you want the first option (start all scripts together). Each script is executing a python program 'script.py'. The post did not specify if there is one script at the initial working directory, or if there are multiple 'script.py', one in each folder. Probably the second option.

If that case, you want to launch you scripts from the process_directory_* folder. Consider making a change to:

( cd process_directory_1 && exec ./start.sh) &
( cd process_directory_2 && exec ./start.sh) &
...

Notes:

  1. All scripts are launched at the same time.
  2. Each script is executed in a different folder, to access the script.py in that folder.
  3. Each job will leave log in the run folder 'nohup.log'.


Answered By - dash-o