12

I have found following in crontab

* * * * * sleep 5; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 10; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 15; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 20; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 25; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 30; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 35; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 40; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 45; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 50; curl -s -m 10 http://url > /dev/null 2>&1
* * * * * sleep 55; curl -s -m 10 http://url > /dev/null 2>&1

so whats the meaning of curl -s -m 10 here ?

0

2 Answers 2

23

From man curl:

--snip--

-m, --max-time <seconds>

Maximum time in seconds that you allow the whole operation to take. This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going down. Since 7.32.0, this option accepts decimal values, but the actual timeout will decrease in accuracy as the specified timeout increases in decimal precision. See also the --connect-timeout option.

If this option is used several times, the last one will be used.

--snip--

-s, --silent

Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

2
  • is that correct way to call any url for every 5 seconds ? as its not working as expected but when I run any url from browser on every 5 seconds my task is working fine
    – Er.KT
    Aug 26, 2016 at 18:38
  • cron has granularity of 1 minute, so it is a way to try to get second granularity.. (it will be every 5 seconds save for each minute where it will got 10 seconds between calling as each has as a sleep. I've never seen this done this way before,thought. If it isn't working there should be a cron log somewhere on the system that logs that is going on, or remove the 2>&1 from the end to get the output..
    – Doon
    Aug 26, 2016 at 18:53
4

If you take a look at the man page for curl, you'll see the following:

 -s, --silent
          Silent  or  quiet  mode. Don't show progress meter or error mes-
          sages.  Makes Curl mute. It will still output the data  you  ask
          for, potentially even to the terminal/stdout unless you redirect
          it.

And:

-m, --max-time <seconds>
          Maximum time in seconds that you allow the whole operation to take.  This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going  down.   Since  7.32.0,  this
          option accepts decimal values, but the actual timeout will decrease in accuracy as the specified timeout increases in decimal precision.  See also the --connect-timeout option.

          If this option is used several times, the last one will be used.

So, curl -s -m 10 means that curl will not show progress or error messages, and will timeout after 10 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.