user3684042
user3684042

Reputation: 671

parallel bash commands with a certain delay in between

I am already familiar with sleep and usleep commands. But I am not sure how to use them for parallel commands which are supposed to have a certain delay with respect to the start time of the previous command. I mean something like this (commands 1 to n are supposed to be run in parallel with a delay between their start time):

Command 1's start time: 0
Command 2's start time: 0+d
Command 3's start time: 0+2d
.
.
.
Command n's start time: 0+(n-1)d

Upvotes: 2

Views: 1313

Answers (1)

dg99
dg99

Reputation: 5663

If you're just running them in the background in the shell then you could simply have each loop sleep after starting its command.

for cmd in cmd1 cmd2 ... cmdN; do
    eval ${cmd} &
    sleep ${d}
done

Upvotes: 3

Related Questions