Martin Myška
Martin Myška

Reputation: 61

Trying to send cURL in BASH more times

i have this BASH script

for I in {1..15}; do curl ..here will be curl.. ; done

For send cURL every 1500ms and 15x but it is not 1500ms,and i do not know how to edit it for it, what im doing bad ?

Upvotes: 3

Views: 1885

Answers (2)

user5211736
user5211736

Reputation:

Adding to Jans answer, you can make the curl run in the background by putting an '&' sign at the end. Can you spawn a process in a shell script?

The result script would then be:

for I in {1..15}
do
  curl stackoverflow.com &
  sleep 1.5
done

It might be worth directing the output to separate files because you may get overlapping outputs if one curl command takes longer than 1.5 seconds.

Upvotes: 3

Jan.J
Jan.J

Reputation: 3080

I order to execute some command every x seconds/milliseconds you must somehow delay your loop. Using sleep is easiest way to do it:

for I in {1..15}
do
  # non-blocking curl command here
  sleep 1.5
done

As default curl command will block execution of loop and times between each loop iteration will be longer and not even. To overcome this you need to prepare curl command that will be non-blocking.

Upvotes: 3

Related Questions