Skip to content
Oh Dear

What is a cron expression? Syntax and examples

A cron expression is a schedule written as five fields: minute, hour, day of month, month and day of week. For example, 0 2 * * * means every day at 02:00 in the scheduler's timezone. The expression describes when to run a task; the command after it describes what to run.

What are cron jobs used for? #

A cron job runs a command at a scheduled time. Common uses include database backups, scheduled emails, data imports, expired-session cleanup, sitemap generation and regular reports.

Use a schedule for recurring work. Work triggered by an event, such as processing a newly uploaded file, usually belongs in a background queue instead. On Windows, Task Scheduler provides another way to schedule tasks; it does not require this five-field syntax.

Finding your existing cron jobs #

On a Linux server, crontab -l lists the current user's cron jobs. Each user has a separate crontab, so jobs owned by another account will not appear in that list. System jobs may also be configured in /etc/cron.d/ or the hourly, daily, weekly and monthly cron directories.

A user crontab entry pairs an expression with a command:

0 2 * * * /home/user/scripts/backup.sh

This runs backup.sh every day at 02:00. The command path is an example; use the path to your own script.

Reading the syntax #

Field Meaning Typical values
First Minute 0 to 59
Second Hour 0 to 23
Third Day of month 1 to 31
Fourth Month 1 to 12
Fifth Day of week 0 to 6, Sunday to Saturday; some implementations also accept 7 for Sunday

An asterisk means every allowed value. A range such as 1-5 selects the values from 1 through 5. A list such as 1,3,5 selects those three values. A step such as */5 selects every fifth value within that field.

Worked example #

0 */4 * * *

This expression runs at minute zero of hours 00, 04, 08, 12, 16 and 20, every day. Steps apply within a field; they are not a timer measured from when the previous run finished.

Common cron expressions #

Expression Schedule
* * * * * Every minute
*/5 * * * * Every five minutes
*/15 * * * * Every fifteen minutes
0 * * * * Every hour, on the hour
0 */4 * * * Every four hours, on the hour
0 0 * * * Every day at midnight
0 2 * * * Every day at 02:00
0 9-17 * * 1-5 Every hour from 09:00 through 17:00, Monday to Friday
0 0 * * 0 Every Sunday at midnight
0 0 1 * * The first day of each month at midnight
0 0 1 1 * January 1 at midnight

These examples use standard five-field cron syntax. Check your scheduler's timezone and daylight-saving behaviour. Syntax extensions vary between schedulers; Oh Dear uses the five-field form. If you restrict both day-of-month and day-of-week, check your scheduler's matching rules rather than assuming both conditions must match.

Use the cron expression tool to inspect a schedule before relying on it.

What about sub-minute schedules? #

Standard five-field cron has minute-level precision. It cannot directly express an interval of 30 seconds. A worker or another scheduler is more suitable when you need work to run more often. Oh Dear's scheduled-task monitoring tracks schedules down to once per minute.

Using cron expressions in Oh Dear #

When configuring scheduled-task monitoring, specify a simple interval in minutes or use a cron expression for a more detailed schedule. Copy only the five schedule fields, without the command.

For this crontab entry:

30 3 * * 1 /home/user/scripts/weekly_backup.sh

Enter this expression in Oh Dear:

30 3 * * 1

The task is expected every Monday at 03:30. Keep the monitoring schedule and timezone aligned with the scheduler that runs the task. Follow the cron job monitoring setup guide to send completion pings.

Monitor whether the job actually ran #

A valid schedule does not prove a task finished. A deployment, unavailable API or changed permission can prevent a job from completing even when its expression is correct.

Log each run and its result. Avoid overlapping runs when a task takes longer than its interval, and document the script's purpose and owner. Send a completion ping only after the work you want to monitor has succeeded.

Oh Dear's scheduled-task monitoring alerts when the expected heartbeat does not arrive within the configured schedule and grace period. A heartbeat confirms that your code sent a ping; it does not independently verify a backup's contents or a report's accuracy.

Related questions & tools

View all Cron Job Monitoring questions →

Want to get started? We offer a no-strings-attached 10 day trial. No credit card required.

You're all set in less than a minute!