Jane S.
Jane S.

Reputation: 245

How to run 2 or more scripts from different directory in parallel

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?

Upvotes: 5

Views: 1915

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207465

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

Upvotes: 3

Arusekk
Arusekk

Reputation: 881

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

(cd $DIR1; $script1) &
(cd $DIR2; $script2) &

Upvotes: 7

Related Questions