How to set up a cron job every 5 minutes and check when it runs

How to set up a cron job every 5 minutes and check when it runs

The schedule for a job that runs every five minutes is one short line, */5 * * * *. The mistakes come from the parts around it: the hour window, the days, and the time zone of the server.

Where a five-minute schedule goes wrong

A cron line has five fields: minute, hour, day of month, month, and day of week. */5 in the minute field means every fifth minute from the start of the hour, so the job runs at :00, :05, :10, and so on up to :55. Write 5 * * * * instead and the job runs once an hour, at minute 5. Nothing warns you, and the job runs twelve times less often than you meant.

Time zones cause the rest of the trouble. The machine that runs cron uses its own time zone, often UTC, and GitHub Actions always runs schedules in UTC. A job limited to 9-17 runs in the server's working hours, not yours. Intervals also restart every hour: with every 7 minutes, the job runs at :56 and again at :00, four minutes later. Five divides 60 evenly, so a five-minute interval never has that short gap.

Build the line, then read it back

Open the Cron Expression Generator and choose Every N minutes under Run. Enter 5, set the hour window to 0 and 23, and tick every day to get */5 * * * *. To run only during working hours, narrow the window and the days: the picker turns the hours 9 to 17 into 9-17 and Monday to Friday into 1-5, which gives */5 9-17 * * 1-5. The page describes the schedule in plain English and lists the next five runs. Press Copy expression and paste the line in front of your command in crontab -e.

To check a line you already have, paste it into the Cron Expression Parser. It explains each of the five fields, writes the schedule in plain English, and lists the next run times in your local time zone or in UTC. Switch to UTC to see what a server set to UTC will actually do. It reads lists, ranges, steps, month and day names such as JAN and SUN, and macros such as @hourly.

Schedule a cron job every 5 minutes

  1. In the Cron Expression Generator, choose Every N minutes and enter 5.
  2. Set the hour window and the days. Keep 0 to 23 and every day for a job that never pauses.
  3. Read the description and the next five runs, then press Copy expression.
  4. Paste the expression into the Cron Expression Parser and show the times in UTC if your server runs on UTC.
  5. Run crontab -e on the server and add the line, such as */5 * * * * /path/to/script.sh.

What a cron line can't handle

  • Both tools use the standard five-field format. Quartz and Spring add a seconds field and don't read these lines as they are.
  • The smallest step in five-field cron is one minute.
  • Around daylight saving changes, a real cron daemon may skip or repeat a run. The run lists show wall-clock times and don't model this.
  • Cron doesn't stop a slow run from overlapping the next one. If a job can take longer than five minutes, add a lock to the script.

Frequently asked questions

What is the cron expression for every 5 minutes?

*/5 * * * *. It runs at minutes 0, 5, 10, and so on up to 55 of every hour.

How do I run a cron job every 5 minutes during working hours only?

Limit the hour and day fields. */5 9-17 * * 1-5 runs every 5 minutes from 09:00 to 17:55, Monday to Friday.

Which time zone does cron use?

The time zone of the machine running the cron daemon, unless the crontab sets CRON_TZ or TZ. GitHub Actions always uses UTC.

Does */5 work in Kubernetes CronJobs and GitHub Actions?

Yes. Both use the standard five-field format.

Tools used in this guide

  • Cron Expression GeneratorDeveloper Tools

    Build a crontab schedule from a frequency picker or field by field, with a description and next runs.

  • Cron Expression ParserDeveloper Tools

    Explains cron schedules in plain English and lists the next run times.

More from the blog

All guides