Curl Command to Repeat URL Request

LinuxUrlCurl

Linux Problem Overview


Whats the syntax for a linux command that hits a URL repeatedly, x number of times. I don't need to do anything with the data, I just need to replicate hitting refresh 20 times in a browser.

Linux Solutions


Solution 1 - Linux

You could use URL sequence substitution with a dummy query string (if you want to use CURL and save a few keystrokes):

curl http://www.myurl.com/?[1-20]

If you have other query strings in your URL, assign the sequence to a throwaway variable:

curl http://www.myurl.com/?myVar=111&fakeVar=[1-20]

Check out the URL section on the man page: https://curl.haxx.se/docs/manpage.html

Solution 2 - Linux

for i in `seq 1 20`; do curl http://url; done

Or if you want to get timing information back, use ab:

ab -n 20 http://url/

Solution 3 - Linux

You might be interested in Apache Bench tool which is basically used to do simple load testing.

example :

ab -n 500 -c 20 http://www.example.com/

> n = total number of request, c = number of concurrent request

Solution 4 - Linux

If you want to add an interval before executing the cron the next time you can add a sleep

> for i in {1..100}; do echo $i && curl "http://URL" >> /tmp/output.log && sleep 120; done

Solution 5 - Linux

You can use any bash looping constructs like FOR, with is compatible to Linux and Mac.

https://tiswww.case.edu/php/chet/bash/bashref.html#Looping-Constructs

In your specific case you can define N iterations, with N is a number defining how many curl executions you want.

for n in {1..N}; do curl <arguments>; done

ex:

for n in {1..20}; do curl -d @notification.json -H 'Content-Type: application/json' localhost:3000/dispatcher/notify; done

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmathematicianView Question on Stackoverflow
Solution 1 - LinuxalexmView Answer on Stackoverflow
Solution 2 - Linuxmatt bView Answer on Stackoverflow
Solution 3 - LinuxAvichal BadayaView Answer on Stackoverflow
Solution 4 - LinuxSharath RaghavanView Answer on Stackoverflow
Solution 5 - LinuxLazaro Fernandes Lima SuleimanView Answer on Stackoverflow