Home > database >  Using xargs to make parallel curl API calls
Using xargs to make parallel curl API calls

Time:08-16

When i run the following command:

seq 1 1 | xargs -I % -P 5 curl -k --user user:pass "https://localhost:port/api"

I only get one response back. I would have expected to get 5 responses since i'm running the curl command 5 times in parallel.

Is this correct or should i see 5 responses?

CodePudding user response:

The problem is on your seq command the range is from 1 to 1.

Try seq 1 5 instead.

CodePudding user response:

You don't really need to specify & repeat number of processes in -P option. Just use -P 0 to allow it to run as many processes as possible. You also don't need to use seq, just use printf like this in process substitution:

xargs -I % -P 0 curl -k --user user:pass "https://localhost:port/api" \
< <(printf '%s\n' {1..5})
  • Related