Cron Expression Syntax and Examples
Learn cron expressions with practical examples, syntax explanations, troubleshooting tips, FAQs, and a browser-based cron expression generator.
Table of Contents
- What Is a Cron Expression?
- Cron Syntax Explained
- Cron Special Characters
- Common Cron Examples
- Advanced Cron Expressions
- Where Cron Is Used
- Linux Cron Tutorial
- GitHub Actions Cron
- Kubernetes CronJob
- Node.js Cron
- Python Scheduling
- Cron Best Practices
- Common Cron Mistakes
- Cron Cheat Sheet
- Cron vs Other Scheduling Systems
- Frequently Asked Questions
- Free Cron Generator
What Is a Cron Expression?
A cron expression is a scheduling format used to automate recurring tasks.
Cron originated in Unix systems and is now used across:
- Linux servers
- Cloud platforms
- Kubernetes clusters
- CI/CD pipelines
- Application schedulers
- DevOps automation workflows
Instead of manually running repetitive tasks, cron automatically executes commands based on a schedule.
Example:
0 9 * * 1-5Meaning:
Run every weekday at 9:00 AM.
Typical cron use cases include:
- Database backups
- Log cleanup
- Email notifications
- Report generation
- Data synchronization
- Security scans
- Cache clearing
Cron Syntax Explained
A standard cron expression contains five fields.
* * * * *
| | | | |
| | | | +-- Day of Week (0-6)
| | | +---- Month (1-12)
| | +------ Day of Month (1-31)
| +-------- Hour (0-23)
+---------- Minute (0-59)Field Breakdown
| Field | Allowed Values |
|---|---|
| Minute | 0-59 |
| Hour | 0-23 |
| Day of Month | 1-31 |
| Month | 1-12 |
| Day of Week | 0-6 (Sunday=0) |
Example:
30 14 * * *Runs every day at 2:30 PM.
Cron Special Characters
Asterisk (*)
Represents every value.
* * * * *Runs every minute.
Comma (,)
Specifies multiple values.
0 9 * * 1,3,5Runs on Monday, Wednesday, and Friday.
Hyphen (-)
Defines a range.
0 9-17 * * *Runs hourly between 9 AM and 5 PM.
Slash (/)
Defines intervals.
*/5 * * * *Runs every five minutes.
Combined Expressions
1,15,30 * * * *Specific minutes.
1-10/2 * * * *Every other value in the range.
Common Cron Examples
Every Minute
* * * * *Every 5 Minutes
*/5 * * * *Every 15 Minutes
*/15 * * * *Every 30 Minutes
*/30 * * * *Every Hour
0 * * * *Every 2 Hours
0 */2 * * *Every Day at Midnight
0 0 * * *Every Day at 9 AM
0 9 * * *Weekdays at 9 AM
0 9 * * 1-5Every Monday at 8 AM
0 8 * * 1First Day of Every Month
0 0 1 * *Every Sunday at Midnight
0 0 * * 0Twice Per Day
0 8,18 * * *Advanced Cron Expressions
Every Quarter
0 0 1 1,4,7,10 *Runs on the first day of each quarter.
Business Hours Monitoring
*/15 9-17 * * 1-5Runs every 15 minutes during business hours.
Every Weekday at 6 PM
0 18 * * 1-5Useful for reporting jobs.
Last Day of Month
Traditional cron does not support:
LSome extended schedulers such as Quartz support this feature.
Where Cron Is Used
| Platform | Usage |
|---|---|
| Linux | crontab |
| macOS | cron |
| Kubernetes | CronJob |
| GitHub Actions | Scheduled workflows |
| Jenkins | Scheduled builds |
| AWS EventBridge | Scheduled events |
| Azure Scheduler | Automation |
| Node.js | node-cron |
| Python | APScheduler |
| Laravel | Task Scheduler |
Linux Cron Tutorial
Edit cron jobs:
crontab -eList cron jobs:
crontab -lDaily backup at 3 AM:
0 3 * * * /home/user/scripts/backup.shGitHub Actions Cron
name: Daily Cleanup
on:
schedule:
- cron: '0 2 * * *'
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm run cleanupKubernetes CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: database-backup
spec:
schedule: '0 2 * * *'Node.js Cron
const cron = require('node-cron');
cron.schedule('0 0 * * *', () => {
console.log('Daily cleanup');
});Python Scheduling
import schedule
import time
def backup():
print("Running backup")
schedule.every().day.at("03:00").do(backup)
while True:
schedule.run_pending()
time.sleep(60)Cron Best Practices
Use Absolute Paths
Bad:
backup.shGood:
/home/user/scripts/backup.shLog Everything
0 2 * * * backup.sh >> backup.log 2>&1Avoid Excessive Frequency
Only use every-minute schedules when truly necessary.
Monitor Job Results
Use:
- Monitoring tools
- Alerts
- Centralized logs
Test Before Production
Validate:
- Syntax
- Permissions
- Runtime environment
Common Cron Mistakes
Timezone Issues
Cron uses the server timezone by default.
Incorrect Field Order
Correct order:
Minute Hour Day Month WeekdaySunday Differences
Some systems use:
0Others also support:
7for Sunday.
Missing Permissions
Ensure scripts are executable.
chmod +x backup.shCron Cheat Sheet
| Schedule | Expression |
|---|---|
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every hour | 0 * * * * |
| Every day | 0 0 * * * |
| Every week | 0 0 * * 0 |
| Every month | 0 0 1 * * |
| Every year | 0 0 1 1 * |
Cron vs Other Scheduling Systems
Cron vs systemd Timers
| Feature | Cron | systemd |
|---|---|---|
| Easy to Learn | Yes | Moderate |
| Logging | Basic | Advanced |
| Dependencies | No | Yes |
| Linux Native | Yes | Yes |
Cron vs Kubernetes CronJob
| Feature | Cron | CronJob |
|---|---|---|
| Cloud Native | No | Yes |
| Scaling | Limited | Excellent |
| Container Aware | No | Yes |
Frequently Asked Questions
What does _/5 _ * * * mean?
It runs every five minutes.
How do I run a cron job every hour?
0 * * * *Does cron support seconds?
Traditional cron does not support seconds.
What timezone does cron use?
Cron uses the server timezone by default.
Why is my cron job not running?
Common causes:
- Wrong path
- Missing permissions
- Environment variables
- Timezone mismatch
- Syntax errors
Try Our Free Cron Generator
Need help building cron schedules?
Use our Cron Expression Generator to:
- Build schedules visually
- Validate cron syntax
- Preview upcoming executions
- Generate expressions instantly
- Copy expressions with one click
Related Tools
Conclusion
Cron remains one of the most reliable scheduling systems available. Once you understand the five fields, special characters, and common scheduling patterns, you can automate almost any recurring task with confidence.
For advanced schedules, use a visual Cron Generator to reduce mistakes and improve productivity.
Keep going