Bash Xargs Sleep (multiple command line arguments)

So, I have the following script that updates Route43 DNS records. Unfortunately, there is a limit to the number of calls per second you can make, so I need the final Xargs command to sleep for about a second between each iteration.

I've tried a couple of things like "{../cli53 blah; sleep 10;} 'and I can't get it to work. Anyone have any suggestions please:

#!/bin/bash

set root='dirname $0'
ec2-describe-instances -O ******* -W ******* --region eu-west-1 |
perl -ne '/^INSTANCE\s+(i-\S+).*?(\S+\.amazonaws\.com)/
and do { $dns = $2; print "$1 $dns\n" }; /^TAG.+\sName\s+(\S+)/
and print "$1 $dns\n"' |
perl -ane 'print "$F[0] CNAME $F[1] --replace\n"' |
grep -v 'i-' | xargs --verbose -n 4 /usr/local/bin/cli53 rrcreate -x 5 contoso.com

      


Edit: Thanks to Etan for the answer. Here is my solution for anyone else who needs it:

I had to include the -I% variable% in the xargs statement to make sure the feed was passed as parameters to cli53, but everything looks fine, good now.

#!/bin/bash

set root='dirname $0'
ec2-describe-instances -O ******* -W ******* --region eu-west-1 |
perl -ne '/^INSTANCE\s+(i-\S+).*?(\S+\.amazonaws\.com)/
and do { $dns = $2; print "$1 $dns\n" }; /^TAG.+\sName\s+(\S+)/
and print "$1 $dns\n"' |
perl -ane 'print "$F[0] CNAME $F[1] --replace\n"' |
grep -v '^i-' |
xargs --verbose -n 4 -I myvar /bin/sh -c '{ /usr/local/bin/cli53 rrcreate -x 5 contoso.com 'myvar'; sleep 1; printf "\n\n"; }'

      

+3


source to share


1 answer


The simplest solution would be to simply place calls cli53

and sleep

in the script and use xargs

to perform the script.

If you don't want to do this, you should be able to do what you tried to do with this:



... | xargs ... /bin/sh -c '{ /usr/local/bin/cli53 ... "$@"; sleep 10; }' -

      

+2


source







All Articles