Add wait between parallel processes in bash
If the upload takes a random amount of time you just need the first 5 to start with a 1-5 second delay:
cat list | parallel -j5 [ {#} -lt 6 ] \&\& sleep {#}\; upload {}
Rather than using xargs, I think you just want a loop, as in
for i in {1..5}; do sleep 5; your-command & done
This forks off the commands every 5 seconds. For an increasing delay (if that's needed):
for i in {1..5}; do ((w=i*5)); sleep $w; your-command & done
Another alternative:
files="a.txt b.txt c.txt"for i in $files; do upload-command $i& sleep 5; done
This might work for you (uses GNU parallel):
find . -type f -name "*.txt" -print | parallel 'script {} & sleep 1'
Here's a terminal session showing an example run:
for x in {a..c};do for y in {1..3};do echo $x >>$x;done;donelsa b ccat aaaacat /tmp/job#!/bin/bashsed -i -e '1e date' -e 's/./\U&/' $1sleep 5sed -i '${p;s,.*,date,e}' $1find . -type f -name "?" -print | parallel '/tmp/job {} & sleep 1'cat ?Sat Mar 10 20:25:10 GMT-1 2012AAASat Mar 10 20:25:15 GMT-1 2012Sat Mar 10 20:25:09 GMT-1 2012BBBSat Mar 10 20:25:14 GMT-1 2012Sat Mar 10 20:25:08 GMT-1 2012CCCSat Mar 10 20:25:13 GMT-1 2012
As you can see each job is started a second apart i.e. file c starts at 08 finishes at 13, file b 09 to 14 and file a 10 to 15.