37

I am working with bash and I am trying to make a curl url call in a for loop.

Below is my simple curl call -

curl -v --header "Connection: keep-alive" "localhost:8080/user?userid=52010&client_id=20&attr=0"

And I am trying to make this curl call in for loop 100 times -

for ((i=1;i<=100;i++)); do   curl -v --header "Connection: keep-alive" "localhost:8080/user?uuid=52010&model_id=20&attr=0" done

I tried running above code as it is in the command line but it doesn't work and it gives me like this -

>

Any thoughts what wrong I am doing?

1
  • Ah never mind. When the typo is fixed the error went away. That is the reason the question is closed :) Just to let the OP know :)
    – Ramesh
    May 13, 2014 at 22:13

1 Answer 1

69

You're missing a semicolon after the URL.

It should be:

for ((i=1;i<=100;i++)); do   curl -v --header "Connection: keep-alive" "localhost:8080/user?uuid=52010&model_id=20&attr=0"; done
3
  • 1
    Silly mistake from me. One last question - Is there any way we can sleep between each curl call for few seconds?
    – arsenal
    May 13, 2014 at 20:05
  • 2
    Sure. Just put the sleep command before the done and add an extra semicolon. You can add as many commands as you want this way. for ((i=1;i<=100;i++)); do curl -v --header "Connection: keep-alive" "localhost:8080/user?uuid=52010&model_id=20&attr=0"; sleep 3; done
    – yoonix
    May 13, 2014 at 20:07
  • is there a way to run these API in a loop asynchronously? It seems to me each API call is blocking
    – veritas
    May 9 at 6:56

Not the answer you're looking for? Browse other questions tagged .