I'm using xargs
+ seq
to run a command several thousand times in parrallel.
e.g. running curl
10,000 times with 20 parrallel processes:
seq 1 10000 | xargs -n1 -P20 curl "https://www.example.com/foo"
However xargs
is appending the output of stdin
to the command it runs (which is what it's designed to do by default). So it ends up effectively running:
curl "https://www.example.com/foo" 1
curl "https://www.example.com/foo" 2
curl "https://www.example.com/foo" 3
curl "https://www.example.com/foo" 4
...
which causes my curl
command to error out.
How can I have xargs
"ignore" the stdin
value here and just output a null/empty value?
I tried a for
loop instead but that doesn't run the statements in parallel, which I require.
I also tried formatting the seq
as empty strings (seq -f'' 1 10000
) which outputs 10,000 blank lines correctly, but xargs
ignores this blank input and never runs any commands.
Thanks!
With xargs -I {}
you can place the stdin with another {}
where you want. If you do not position it in the command the stdin is ignored.