DEV Community

Cover image for Saved at 10:03, */5 still runs at 10:05
Ameen Usman
Ameen Usman

Posted on

Saved at 10:03, */5 still runs at 10:05

I saved */5 * * * * at 10:03 and expected a run at 10:08. That is not how the step works. On a five-field crontab the minute field is locked to the clock. */5 steps through 0–59 by five, starting at 0. The runs are 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55. From 10:03 the next fire is 10:05, then 10:10.

Build the same line in the cron expression generator. The page does not install the job. Copy the expression into the crontab on the host that will run it.

The same idea at other steps

*/5 * * * *     # 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
*/10 * * * *    # 0, 10, 20, 30, 40, 50
*/15 * * * *    # 0, 15, 30, 45
*/30 * * * *    # 0 and 30
Enter fullscreen mode Exit fullscreen mode

Each of those still includes minute 0. 5-59/5 * * * * does not. Use that only when the top of the hour should stay quiet.

Mistakes that move the run

There is no seconds field. Quartz puts seconds first and shifts everything else. EventBridge uses six fields without seconds and puts ? in a day field. A five-field line from this site matches neither shape.

On Vixie cron and cronie, 0 0 */5 * * is midnight on the 1st, 6th, 11th, 16th, 21st, 26th, and 31st. It is not “every date divisible by 5.”

Classic cron does not skip a run because the previous process is still going. A six-minute command on */5 overlaps itself. Take a lock inside the command if that must not happen, and call the program by its absolute path. Cron’s PATH is often short.

*/5 also cannot mean “five minutes from now.” Use a sleep or a queue delay for that.

One cycle on the host

*/5 * * * * date >> /tmp/cron-every-5.log
Enter fullscreen mode Exit fullscreen mode

Wait for two lines. The minutes should be five apart and divisible by 5. Then delete the line.

Guide: https://kepttools.com/guides/cron-every-5-minutes

Top comments (0)