fjordtools / Errors / Cron: every N minutes

Cron every N minutes (*/N)

A step like */7 does not mean every seven minutes since the last run. Cron lists the minutes 0, 7, 14 and so on up to 56, then starts over at 0 in the next hour, so one gap is only four minutes. Only values that divide 60, such as 5, 10, 15 and 30, give an even rhythm. The same holds for hours.

Fjordtools team · Seen in Vixie-style cron on Linux and macOS · Published · 1 min read

Common causes

  1. A step that divides 60

    Every 5, 10, 15, 20 or 30 minutes lines up with the hour and the rhythm is even.

    Input

    */5 * * * *

    Cron Explainer says

    Every 5 minutes
  2. A step that does not divide 60

    */7 runs at minutes 0, 7, 14, 21, 28, 35, 42, 49 and 56. Then the hour ends and it runs again at minute 0, four minutes after the last one.

    Input

    */7 * * * *

    Cron Explainer says

    Every 7 minutes, restarting each hour
  3. The same rule for hours

    */5 in the hour field means hours 0, 5, 10, 15 and 20. After 20:00 the next run is at 00:00, four hours later, not five.

    Input

    0 */5 * * *

    Cron Explainer says

    At minute 0, every 5 hours (restarting each day)
  4. Every minute

    Five stars run every minute. */1 means the same.

    Input

    * * * * *

    Cron Explainer says

    Every minute

How to fix it

  1. Pick a step that divides 60 (or 24 for hours), or list the minutes yourself: 0,20,40.
  2. For an interval cron cannot express, run every 30 minutes and have the script check the time since its last run.
  3. Use a systemd timer with OnUnitActiveSec if the gap must be exact.
  4. Paste the line into the cron explainer: it lists the next run times, so an uneven gap is visible.

Related errors

More error explainers are coming

See all errors.