← Back to Blog DevOps

How to Write a Cron Expression — From Basics to Every-5-Minute Schedules

Cron is the silent scheduler behind most automated infrastructure. It controls when backups run, when logs rotate, when health checks fire, and when reports get generated. But the expression syntax — five terse fields packed with asterisks, slashes, and commas — trips up even experienced engineers. This guide breaks the format down field by field, with copy-paste examples for the schedules developers need most.

The Five Fields

Every standard cron expression has exactly five fields, read left to right:

┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12)
│ │ │ │ ┌─ day of week (0–7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Each field accepts a number, a wildcard (* = every), a range (1-5), a list (1,3,5), or a step value (*/10 = every 10th).

Common Schedules With Examples

Every 5 Minutes

*/5 * * * *

The */5 in the minute field means "at minute 0, 5, 10, 15…55." The remaining wildcards let it run every hour, every day. This is the most searched cron pattern — useful for health checks, queue workers, and lightweight polling tasks.

Every Day at Midnight

0 0 * * *

Runs once at 00:00 server time. Common for log rotation, database dumps, and cleanup scripts.

Every Monday at 9 AM

0 9 * * 1

The 1 in the weekday field means Monday. Useful for weekly report generation or sprint-start notifications.

First Day of Every Month at 6 AM

0 6 1 * *

The 1 in the day-of-month field triggers on the first. Great for billing summaries and monthly audit exports.

Every 30 Seconds (Workaround)

Standard cron doesn't support sub-minute intervals. The common workaround is two entries offset by 30 seconds using sleep in the command itself:

* * * * * /path/to/script.sh
* * * * * sleep 30 && /path/to/script.sh

Special Characters Quick Reference

CharacterMeaningExample
*Every value* * * * * = every minute
*/nEvery nth value*/15 * * * * = every 15 min
a-bRange0 9-17 * * * = hourly 9AM–5PM
a,bList0 6,18 * * * = 6AM and 6PM

Common Mistakes

  • Forgetting timezone. Cron uses server time unless explicitly configured. An AWS Lambda cron in UTC will fire at a different wall-clock time than a local crontab.
  • Day-of-month AND day-of-week. Setting both fields creates an OR condition, not AND. 0 0 15 * 1 runs on the 15th AND every Monday — not just Mondays that fall on the 15th.
  • Using 0 vs 7 for Sunday. Both are valid, but mixing them in the same team or config set leads to confusion. Pick one and stick with it.

Build It Visually

If you'd rather build and preview cron expressions without memorizing the syntax, try the Cron Job Generator. It shows the next scheduled run times in real time, runs entirely in your browser, and doesn't upload anything.

Frequently Asked Questions

What is a cron expression?
A cron expression is a string of five (or six) fields separated by spaces that tells a scheduler exactly when to run a task. The fields represent minute, hour, day of month, month, and day of week.
How do I write a cron expression for every 5 minutes?
Use */5 * * * * — the */5 in the minute field means "every 5th minute", and the wildcards mean "every hour, every day, every month, every weekday."
What does the asterisk mean in cron?
An asterisk (*) means "every possible value" for that field. For example, * in the hour field means every hour.
Can I test cron expressions without deploying?
Yes. Use a browser-based cron expression generator to build, validate, and preview the next run times before adding the expression to your system.