Search code examples
curlrequest

How can I run multiple curl requests processed sequentially?


Assuming I'm a big Unix rookie:

  • I'm running a curl request through cron every 15 minutes.

  • Curl basically is used to load a web page (PHP) that given some arguments, acts as a script like:

    curl http://example.com/?update_=1
    

What I would like to achieve is to run another "script" using this curl technique,

  • every time the other script is run
  • before the other script is run

I have read that curl accepts multiple URLs in one command, but I'm unsure if this would process the URLs sequentially or in "parallel".


Solution

  • It would most likely process them sequentially (why not just test it). But you can also do this:

    1. make a file called curlrequests.sh

    2. put it in a file like thus:

      curl http://example.com/?update_=1
      curl http://example.com/?update_=3
      curl http://example.com/?update_=234
      curl http://example.com/?update_=65
      
    3. save the file and make it executable with chmod:

      chmod +x curlrequests.sh
      
    4. run your file:

      ./curlrequests.sh
      

    or

       /path/to/file/curlrequests.sh
    

    As a side note, you can chain requests with &&, like this:

       curl http://example.com/?update_=1 && curl http://example.com/?update_=2 && curl http://example.com?update_=3`
    

    And execute in parallel using &:

       curl http://example.com/?update_=1 & curl http://example.com/?update_=2 & curl http://example.com/?update_=3