Search code examples
croncron-task

How the cron timing is working?


Suppose, current time is 11:42 and i have setup one cron file to run at every 5 minutes.

Then this file will run at which time 11:47 or 11:45?

So basically i am trying to understand that how the cron timing is work?

Edit : it was ran at 11:45, but i don't know the reason behind it

Cron Configuration :

*/5 * * * * wget -O /dev/null http://XXX/index.php?r=controller/action

Solution

  • As you know, cron will run jobs at a specific time.

    A cron job will not use the time it was started, only the configuration matters. This means a cron job set to every 5 minutes (like your */5 * * * *) will only ever run at times ending with 0 or 5 (eg: 12:00, 12:05, 12:10), regardless of the time you run it. This makes sense because we want to schedule a job for a specific time.

    If you really need a job to run every 5 minutes, with an offset (eg: 11:42, 11:47, 11:52) you will have to give a list in the configuration.

    instead of (*/5 * * * *) you would need to use:

    (2,7,12,...,57 * * * *), filling ... with all the other numbers.