2

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
1
  • How many tasks are there? And what sort of delay are you envisaging? Commented Jan 14, 2015 at 21:11

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

Maybe ad a caveat that the commands should be wrapped in quotes to handle arguments and options. Alternatively execution could be achieved using $(${cmd}) & but this is less stylish.
@ShellFish Good point. I typically write my bash answers lazily and then assume that Gilles or Stephane will wander by at some later date to correct it. :)
Is there a nice way of doing this if the commands are long and full of parameters and quote marks?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.