Cron Expression Guide — Examples & Generator 2026
Up-to-date Feed
View AllHome / Blog / Cron Expression Guide — Examples & Generator 2026
Cron Expression Guide — Examples & Generator 2026
A comprehensive breakdown of cron syntax to automate scripts, database backups, and Kubernetes jobs without error.
Published June 05, 2026 · Last updated June 14, 2026 · By Abu Sufyan, Full-stack Developer & DevOps Engineer
Quick Answer
A standard cron expression consists of 5 fields separated by spaces: Minute, Hour, Day-of-month, Month, and Day-of-week. By placing numbers, asterisks (*), hyphens (-), or slashes (/) in these fields, you can schedule scripts to run at highly specific intervals. For example, */5 * * * * triggers a job every 5 minutes, while 0 2 * * * runs a job every day at 2:00 AM.
👉 Try the Offline Cron Expression Generator → — visually build your schedule and instantly verify the next 5 execution times without reading man pages.
Why This Happens (In-Depth Analysis)
When developers struggle with cron, the issue rarely lies in the syntax itself; the failure usually stems from fundamental misunderstandings of server timezones and execution environments.
Early in my career, I deployed a massive database backup script using a cron job set to 0 2 * * * (2:00 AM daily). I explicitly wanted the backup to happen during the lowest traffic window for our US-based users to avoid locking the production tables. A week later, the database crashed at 9:00 PM EST due to severe IO exhaustion. Why? The AWS EC2 instance was running in UTC. 2:00 AM UTC is exactly 9:00 PM EST—smack in the middle of our platform's prime time.
The core lesson here is that a cron expression is just a dumb string of characters. It has absolutely no awareness of geography, daylight saving time (DST), or user intent. You must rigorously align your cron schedules to the server's local timezone configuration, which in modern 2026 cloud-native architecture should always be firmly locked to UTC.
Furthermore, cron tasks execute in a highly restricted, non-interactive shell. Developers frequently write a script that runs perfectly when they type ./script.sh in their terminal, but fails silently when triggered by cron. This happens because cron does not load your ~/.bashrc or ~/.profile. Environment variables like $PATH or $NODE_ENV are usually missing. If your script relies on /usr/local/bin/node, you must explicitly declare that absolute path within the script or at the top of your crontab file.
How to Fix It (Step-by-Step Tutorial)
To master cron scheduling and eliminate deployment anxiety, you need to understand the field structure and map out your schedule carefully. Here is exactly how to build and validate a standard 5-field cron expression.
1. Understand the 5-Field Syntax
A standard Vixie cron expression consists of five fields. (Note: Systems like AWS CloudWatch or Quartz Java use 6 fields to include seconds or years, but standard Linux and Kubernetes use 5).
* * * * *
│ │ │ │ │
│ │ │ │ └── Day of the week (0 - 7) (0 and 7 are Sunday)
│ │ │ └──── Month (1 - 12)
│ │ └────── Day of the month (1 - 31)
│ └──────── Hour (0 - 23)
└────────── Minute (0 - 59)
Special Characters to Master:
*(Asterisk): Matches all values. (e.g.,*in the hour field means "every hour").,(Comma): Separates items in a list. (e.g.,1,15in the minute field means "at minute 1 and 15").-(Hyphen): Defines a range. (e.g.,9-17in the hour field means "between 9 AM and 17:00 / 5 PM")./(Slash): Specifies step values/increments. (e.g.,*/10in the minute field means "every 10 minutes").
2. Identify and Translate Your Schedule
Translate your human requirement into the 5 fields. Here are 20 heavily used examples you can copy directly into production:
High Frequency
- Every minute:
* * * * * - Every 5 minutes:
*/5 * * * * - Every 15 minutes:
*/15 * * * * - Every 30 minutes:
*/30 * * * *
Hourly Schedules
- Every hour, precisely on the hour:
0 * * * * - Every 2 hours:
0 */2 * * * - At minute 15 past every hour:
15 * * * *
Daily Schedules
- Midnight every day:
0 0 * * * - Every day at 2:30 AM:
30 2 * * * - Every day at 8:00 AM and 8:00 PM:
0 8,20 * * *
Weekly Schedules
- Every Sunday at midnight:
0 0 * * 0 - Every Monday at 9:00 AM:
0 9 * * 1 - Monday through Friday at 5:00 PM (Business close):
0 17 * * 1-5 - Weekends only, at noon:
0 12 * * 0,6
Monthly / Yearly Schedules
- First day of every month at midnight:
0 0 1 * * - 15th of every month at 3:00 AM:
0 3 15 * * - January 1st at midnight (Happy New Year):
0 0 1 1 *
3. Implement in Kubernetes (CronJob Manifests)
If you are writing a Kubernetes CronJob manifest, the syntax is identical to Linux cron. However, Kubernetes adds a crucial execution parameter.
apiVersion: batch/v1
kind: CronJob
metadata:
name: database-backup
spec:
schedule: "0 2 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: backup-image
restartPolicy: OnFailure
If your job takes 10 minutes to run, but your cron is scheduled every 5 minutes, Kubernetes will overlap the pods. Setting concurrencyPolicy: Forbid ensures that a new job will not start if the previous one is still executing.
Faster way: use the Cron Expression Generator
Stop risking production outages on a misunderstood syntax rule. You can visually build complex schedules using our dedicated tool.
Open the Cron Expression Generator — Free, No Signup →
The generator will translate human-readable inputs ("Every Tuesday at 4 AM") into flawless 5-field syntax and output the next 10 execution dates based on your local timezone, completely offline.
Edge Cases Most Guides Miss
The most dangerous, yet least documented, edge case in cron scheduling is The Day/Date OR Trap.
Suppose you want to run a financial audit script on the first of the month, but only if the first of the month is a Monday. A logical developer might write:
0 0 1 * 1
Unfortunately, in standard cron implementations, if both the Day-of-month (field 3) and Day-of-week (field 5) are specified, the cron daemon treats them as an OR operator, not an AND operator.
Therefore, 0 0 1 * 1 translates to: "Run at midnight on the first of the month, OR run at midnight every Monday." Your script will execute every single Monday, plus the 1st of every month, wreaking havoc on your financial reporting.
To solve this, you must schedule the job to run every Monday (0 0 * * 1), and inside your actual bash or Python script, write a conditional statement to check if today's date is the 1st. [ "$(date +\%d)" = "01" ] || exit 0.
Another massive edge case is daylight saving time (DST) transitions. If you schedule a job for 2:30 AM local time, what happens in Spring when the clock jumps from 1:59 AM to 3:00 AM? The job skips entirely. What happens in Autumn when 2:30 AM happens twice? The job runs twice. The only permanent fix is migrating the host operating system strictly to UTC.
Comprehensive FAQ
What does */5 * * * * mean?
It means the job will run every 5 minutes, at the 0, 5th, 10th, 15th (and so on) minute of every hour, every day.
How do I run a cron job every second?
Standard cron expressions only resolve down to the minute. You cannot run a job every second using standard Linux cron. You would need to write a custom daemon, use a Systemd timer, or write a bash script containing a while true; do ./script.sh; sleep 1; done loop.
Why is my cron script failing when it runs manually fine?
Cron executes jobs in a restricted environment where standard environment variables (like $PATH) are missing. Always use absolute paths (e.g., /usr/bin/python3 /var/scripts/task.py) and source your .bashrc explicitly inside the script if you need those variables.
Do cron jobs overlap if the previous run hasn't finished?
Yes. Linux cron will blindly start a new process at the scheduled time regardless of whether the last script is still running. You must use tools like flock (file locking) inside your script to prevent concurrent executions, or use Kubernetes concurrencyPolicy: Forbid.
About the Author
Abu Sufyan — Full-stack Developer and DevOps Engineer. Founder of WebToolkit Pro. Specializes in cloud-native architecture, Kubernetes deployments, and automated infrastructure pipelines. GitHub · Portfolio
Related tools:
- Docker Compose Generator — Scaffold multi-container microservices instantly.
- JSON Formatter — Securely format your application configuration files offline.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Cron Expression Guide — Examples & Generator 2026",
"description": "Master cron expression syntax with 20 ready-to-use examples. Learn how to handle timezones, Kubernetes scheduling, and debug complex CRON strings securely.",
"datePublished": "2026-06-05",
"dateModified": "2026-06-14",
"author": {
"@type": "Person",
"name": "Abu Sufyan",
"url": "https://github.com/abusufyan-netizen"
},
"publisher": {
"@type": "Organization",
"name": "WebToolkit Pro",
"url": "https://wtkpro.site"
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://wtkpro.site/blog/cron-expression-guide-examples/"
}
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What does `*/5 * * * *` mean?",
"acceptedAnswer": {
"@type": "Answer",
"text": "It means the job will run every 5 minutes, at the 0, 5th, 10th, 15th (and so on) minute of every hour, every day."
}
},
{
"@type": "Question",
"name": "How do I run a cron job every second?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Standard cron expressions only resolve down to the minute. You cannot run a job every second using standard Linux cron. You would need to write a custom daemon, use a Systemd timer, or write a bash script containing a sleep loop."
}
},
{
"@type": "Question",
"name": "Why is my cron script failing when it runs manually fine?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Cron executes jobs in a restricted environment where standard environment variables (like $PATH) are missing. Always use absolute paths and source your .bashrc explicitly inside the script if you need those variables."
}
},
{
"@type": "Question",
"name": "Do cron jobs overlap if the previous run hasn't finished?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes. Linux cron will blindly start a new process at the scheduled time regardless of whether the last script is still running. You must use tools like flock inside your script to prevent concurrent executions."
}
}
]
}
Cron Expression Generator
Build cron schedules visually and get a plain-English description instantly.
wtkpro.site
WebToolkit Pro Team
Contributing Author