How to Validate Cron Expressions: A Step-by-Step Guide
How to Validate Cron Expressions
Cron expressions are compact but easy to get wrong. A misplaced slash or out-of-range value can cause a job to run at the wrong time — or not at all. Validating expressions before deployment saves hours of debugging when a critical task silently fails.
Common Syntax Errors
Out-of-Range Values
Each field accepts a specific range. Values outside this range are invalid.
# Invalid: minute 60 is out of range (0-59)
60 * * * *
# Invalid: hour 24 is out of range (0-23)
0 24 * * *
Missing Fields
A cron expression requires exactly five fields. Four fields is invalid, six fields requires extended syntax.
# Invalid: only 4 fields (missing day of week)
0 0 * *
# Invalid: 6-field syntax without proper daemon support
0 0 * * * * /command.sh
Always count: minute, hour, day-of-month, month, day-of-week.
Incorrect Step Values
# Invalid: cannot step by 0
*/0 * * * *
# Invalid: step exceeds field maximum
*/61 * * * *
Step values must start at 1 and not exceed the field's maximum.
How to Validate a Cron Expression
Step 1: Parse into Fields
Split on spaces and verify exactly five fields:
Expression: 30 6 * * 1-5
Fields: minute=30, hour=6, day=*, month=*, weekday=1-5
Step 2: Validate Each Field
| Field | Allowed Range | Accepts Special Chars |
|-------|--------------|-----------------------|
| Minute | 0-59 | * , - / |
| Hour | 0-23 | * , - / |
| Day of Month | 1-31 | * , - / |
| Month | 1-12 | * , - / |
| Day of Week | 0-7 | * , - / |
Step 3: Check for Conflicts
Some expressions are syntactically valid but logically surprising:
# Runs on the 15th OR every Sunday — an OR condition
0 0 15 * 0
Day-of-month and day-of-week together create an OR condition in standard cron. The job runs when either matches.
Step 4: Preview Upcoming Times
Generate execution times to visually verify your schedule:
Expression: 0 2 * * 1
Next 5 executions:
1. 2026-07-27 02:00:00 (Monday)
2. 2026-08-03 02:00:00 (Monday)
3. 2026-08-10 02:00:00 (Monday)
If the preview does not match your intent, fix the expression before production.
Debugging Non-Executing Jobs
A valid expression that does not run is usually a system issue:
- Permissions — the script must have execute permission (
chmod +x). - Path — cron uses a minimal PATH. Always use absolute paths:
/usr/local/bin/mybackup.shnotmybackup.sh. - Environment — cron does not load shell profiles. Export variables within the crontab or the script itself.
- Logging — redirect output to confirm execution:
0 6 * * * /path/to/script.sh >> /var/log/cron.log 2>&1
Using the Validator Tool
The cron expression validator provides three functions:
- Syntax validation — immediate feedback on field values and formatting.
- Schedule preview — view upcoming execution times from the current date.
- Visual calendar — scheduled executions plotted on a monthly calendar.
No cron expression should be deployed without previewing the next several execution times. A thirty-second check prevents silent scheduling failures.