4

As of now I a using time parallel to run scripts in parallel. Example... First, I'll go to the directory where the scripts are located.

cd $DIR

Then, execute scripts

time parallel ::: $script1 $script2 $script3

This works well.

But what if the scripts are in different directory?

Jane S.
  • 215
  • 1
  • 4
  • 12

2 Answers2

6

You can use an ampersand (&) for background execution in bash, and (command) to run command in a subshell:

(cd $DIR1; $script1) &
(cd $DIR2; $script2) &
Arusekk
  • 827
  • 4
  • 22
3

If you don't need to cd into each directory, you can simply do:

time parallel --dry-run ::: dirA/dirB/script1 dirC/dirD/script2

Sample Output

dirA/dirB/script1
dirC/dirD/script2

If you do need to cd into each directory, you can do it like this:

time parallel --dry-run 'cd {//} && {/}' ::: dirA/dirB/script1 dirC/dirD/script2

Sample Output

cd dirA/dirB && script1
cd dirC/dirD && script2
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432