How to Run a cURL Command Every N Seconds
How can we run a cURL command every
Suppose we want to run the following cURL command every
curl -d "index=0" -X POST https://example.com
However, let’s also increment the index on every cURL command.
Check out this article to learn more about POST requests with cURL.
Let’s create a bash script to achieve this functionality.
#!/bin/bash INDEX=0 while sleep 2 do curl -d "index=$INDEX" -X POST https://example.com ((INDEX++)) done
We can start our loop with
while sleep 2, which will run the
do block every
We’ll pass the
INDEX variable into our
-d argument using
Then, we’ll increment that variable using
If we want to send the cURL commands as quickly as possible, we can simply run the loop