DevToolBoxฟรี
บล็อก

Crontab Cheat Sheet 2025: 50+ ตัวอย่าง Cron Expression ที่ใช้จริง

12 นาทีโดย DevToolBox

Whether you are scheduling backups, automating deployments, or running periodic cleanup scripts, cron is the backbone of task scheduling on Unix/Linux systems. This cheat sheet gives you 50+ copy-paste cron expression examples organized by frequency, plus crontab commands, platform differences, and common gotchas.

1. Cron Expression Syntax

A standard cron expression consists of 5 fields separated by spaces. Each field controls when the job runs:

┌───────────── Minute (0–59)
│ ┌─────────── Hour (0–23)
│ │ ┌───────── Day of Month (1–31)
│ │ │ ┌─────── Month (1–12 or JAN–DEC)
│ │ │ │ ┌───── Day of Week (0–7 or SUN–SAT, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *  command_to_execute

The command to execute follows the five fields. Use our Cron Generator tool to build expressions visually.

Cron Generator Tool →

2. Special Characters Explained

Cron uses four special characters to define schedules beyond fixed values:

CharacterMeaningExampleDescription
*Matches every possible value for the field* * * * *Every minute
,Specifies a list of values (e.g., 1,3,5)0 9 * * 1,3,5Mon, Wed, Fri at 9 AM
-Defines an inclusive range (e.g., 1–5 means 1 through 5)0 9 * * 1-5Mon through Fri at 9 AM
/Defines a step interval (e.g., */5 means every 5 units)*/10 * * * *Every 10 minutes

3. 50+ Cron Expression Examples

The tables below cover the most commonly needed cron schedules. Each expression is ready to copy and paste into your crontab.

Every X Minutes

ExpressionDescriptionNext Run Example
* * * * *Every minute10:00, 10:01, 10:02 ...
*/1 * * * *Every minute (explicit)10:00, 10:01, 10:02 ...
*/2 * * * *Every 2 minutes10:00, 10:02, 10:04 ...
*/5 * * * *Every 5 minutes10:00, 10:05, 10:10 ...
*/10 * * * *Every 10 minutes10:00, 10:10, 10:20 ...
*/15 * * * *Every 15 minutes10:00, 10:15, 10:30, 10:45
*/20 * * * *Every 20 minutes10:00, 10:20, 10:40 ...
*/30 * * * *Every 30 minutes10:00, 10:30, 11:00 ...
0,15,30,45 * * * *At 0, 15, 30, 45 minutes past each hour10:00, 10:15, 10:30, 10:45

Hourly Schedules

ExpressionDescriptionNext Run Example
0 * * * *Every hour (at minute 0)10:00, 11:00, 12:00 ...
30 * * * *Every hour at minute 3010:30, 11:30, 12:30 ...
15 * * * *Every hour at minute 1510:15, 11:15, 12:15 ...
0 */2 * * *Every 2 hours00:00, 02:00, 04:00 ...
0 */3 * * *Every 3 hours00:00, 03:00, 06:00 ...
0 */4 * * *Every 4 hours00:00, 04:00, 08:00 ...
0 */6 * * *Every 6 hours00:00, 06:00, 12:00, 18:00
0 */8 * * *Every 8 hours00:00, 08:00, 16:00
0 */12 * * *Every 12 hours00:00, 12:00

Daily Schedules

ExpressionDescriptionNext Run Example
0 0 * * *Daily at midnight (00:00)Tomorrow 00:00
0 1 * * *Daily at 1:00 AMTomorrow 01:00
0 6 * * *Daily at 6:00 AMTomorrow 06:00
30 7 * * *Daily at 7:30 AMTomorrow 07:30
0 9 * * *Daily at 9:00 AMTomorrow 09:00
30 8 * * *Daily at 8:30 AMTomorrow 08:30
0 12 * * *Daily at noon (12:00)Tomorrow 12:00
0 15 * * *Daily at 3:00 PMTomorrow 15:00
0 18 * * *Daily at 6:00 PMTomorrow 18:00
0 23 * * *Daily at 11:00 PMTomorrow 23:00
0 8-17 * * *Every hour from 8 AM to 5 PM08:00, 09:00 ... 17:00
0 9,12,18 * * *Three times a day (9 AM, noon, 6 PM)09:00, 12:00, 18:00

Weekly Schedules

ExpressionDescriptionNext Run Example
0 9 * * 1Every Monday at 9:00 AMNext Monday 09:00
0 9 * * 1-5Weekdays (Mon-Fri) at 9:00 AMNext weekday 09:00
0 0 * * 0Every Sunday at midnightNext Sunday 00:00
0 0 * * 6,0Saturday & Sunday at midnightNext Sat/Sun 00:00
0 17 * * 5Every Friday at 5:00 PMNext Friday 17:00
0 9 * * 1,3,5Mon, Wed, Fri at 9:00 AMNext Mon/Wed/Fri 09:00
0 8-17 * * 1-5Hourly 8AM–5PM, weekdays onlyNext weekday 08:00
30 6 * * 1-5Weekdays at 6:30 AMNext weekday 06:30

Monthly Schedules

ExpressionDescriptionNext Run Example
0 0 1 * *1st of every month at midnightNext month, 1st 00:00
0 0 15 * *15th of every month at midnightNext 15th 00:00
0 9 1 * *1st of every month at 9:00 AMNext month, 1st 09:00
0 0 1,15 * *1st and 15th at midnightNext 1st or 15th 00:00
0 0 * * 5LLast Friday of the month (non-std)Last Fri 00:00
0 9 * * 1#1First Monday of the month (non-std)First Mon 09:00
0 0 28 * *28th of every month at midnightNext 28th 00:00

Yearly / Quarterly Schedules

ExpressionDescriptionNext Run Example
0 0 1 1 *January 1st at midnightJan 1 00:00
0 0 1 1,4,7,10 *Quarterly: Jan, Apr, Jul, Oct 1stNext quarter 00:00
0 0 1 1,7 *Bi-annually: Jan 1 & Jul 1Jan 1 or Jul 1 00:00
0 0 25 12 *December 25th at midnightDec 25 00:00
0 0 1 */3 *Every 3 months on the 1stNext 1st in 3 months
0 0 1 */6 *Every 6 months on the 1stNext 1st in 6 months

Business & DevOps Schedules

ExpressionDescriptionNext Run Example
0 2 * * *Database backup at 2:00 AM dailyTomorrow 02:00
0 3 * * 0Log rotation every Sunday at 3 AMNext Sunday 03:00
0 4 1 * *Monthly DB cleanup on 1st at 4 AMNext month, 1st 04:00
0 1 * * *SSL cert check daily at 1 AMTomorrow 01:00
*/5 * * * *Health check every 5 minutes10:00, 10:05, 10:10 ...
0 5 * * 1-5Deploy window: weekdays at 5 AMNext weekday 05:00
0 0 * * *Rotate logs daily at midnightTomorrow 00:00
0 */4 * * *Send report digest every 4 hours00:00, 04:00, 08:00 ...
0 22 * * 5Friday night maintenance at 10 PMNext Friday 22:00
30 2 * * *Temp file cleanup at 2:30 AM dailyTomorrow 02:30
Cron Expression Parser Tool →

4. Crontab Commands Quick Reference

The crontab command manages per-user cron job files. Here are the essential commands:

CommandWhat It Does
crontab -eEdit your crontab file (opens in default editor)
crontab -lList all cron jobs for the current user
crontab -rRemove all cron jobs for the current user (use with caution!)
crontab -u alice -lList cron jobs for a specific user (requires root)
crontab -u alice -eEdit crontab for a specific user (requires root)
crontab filenameInstall a crontab from a file (overwrites existing)
# Edit crontab
crontab -e

# List all cron jobs
crontab -l

# Backup current crontab to a file
crontab -l > my-crontab-backup.txt

# Install crontab from a file
crontab my-crontab-backup.txt

# Remove all cron jobs (careful!)
crontab -r
Crontab Generator Tool →

5. Platform-Specific Cron Syntax

Cron syntax varies slightly across platforms. Here are the key differences you need to know:

Linux crontab (standard)

5 fields: minute hour day month weekday. The original and most common format.

# Standard 5-field crontab
*/5 * * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
GitHub Actions

Standard 5 fields in schedule.cron. Always runs in UTC. Minimum interval: 5 minutes.

# .github/workflows/scheduled.yml
on:
  schedule:
    - cron: '0 9 * * 1-5'  # Weekdays 9AM UTC
AWS CloudWatch / EventBridge

6 fields (adds year). Uses ? for day-of-week or day-of-month. Wrapped in cron().

# AWS EventBridge (6 fields, note the ?)
cron(0 9 ? * MON-FRI *)  # Weekdays 9AM UTC
Kubernetes CronJob

Standard 5 fields in the schedule spec. Timezone support added in K8s 1.27+ via timeZone.

# Kubernetes CronJob spec
apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-backup
spec:
  schedule: "0 2 * * *"
  timeZone: "America/New_York"  # K8s 1.27+
Vercel Cron

Standard 5 fields in vercel.json. Runs in UTC. Hobby plan: max 2 cron jobs, 1/day minimum.

// vercel.json
{
  "crons": [{
    "path": "/api/cron/daily-report",
    "schedule": "0 9 * * *"
  }]
}

6. Cron Expression Gotchas

These are the most common mistakes developers make with cron schedules:

1
Timezone Confusion

Cron runs in the system timezone by default. CI/CD platforms (GitHub Actions, Vercel) use UTC. Always check which timezone your cron daemon uses.

2
Overlapping Executions

If a job takes longer than the interval (e.g., a 10-minute job on a 5-minute schedule), you get overlapping runs. Use flock or a PID lock file to prevent this.

3
Daylight Saving Time

When clocks spring forward, a job scheduled at the skipped hour will not run. When clocks fall back, it may run twice. Use UTC to avoid this.

4
Day-of-Month AND Day-of-Week

In standard cron, if both day-of-month and day-of-week are set (not *), the job runs when EITHER matches — not both. This is a common source of confusion.

5
No Seconds Support

Standard cron does not support seconds. The minimum resolution is 1 minute. For sub-minute scheduling, use a loop with sleep inside a cron job.

6
Environment Variables

Cron jobs run with a minimal environment. Your $PATH may not include expected binaries. Always use full paths in cron commands.

# Gotcha: overlapping runs - use flock to prevent
*/5 * * * * /usr/bin/flock -n /tmp/myjob.lock /path/to/script.sh

# Gotcha: environment - always use full paths
0 2 * * * /usr/bin/python3 /home/user/scripts/backup.py >> /var/log/backup.log 2>&1

# Gotcha: 30-second workaround (two entries)
* * * * * /path/to/script.sh
* * * * * sleep 30 && /path/to/script.sh

# Gotcha: PATH not set - define it at the top of your crontab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Gotcha: percent signs (%) must be escaped in crontab
# Wrong:
0 0 * * * echo "Today is $(date +%Y-%m-%d)"
# Correct:
0 0 * * * echo "Today is $(date +\%Y-\%m-\%d)"

Sample Crontab File

Here is a complete, real-world crontab file combining several patterns discussed above:

# =============================================
# Crontab for: webserver (production)
# Last updated: 2025-01-15
# =============================================

# Environment
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAILTO="ops-team@example.com"

# --- BACKUPS ---
# Full database backup at 2:00 AM daily
0 2 * * * /usr/bin/flock -n /tmp/db-backup.lock /opt/scripts/db-backup.sh >> /var/log/db-backup.log 2>&1

# Incremental file backup every 6 hours
0 */6 * * * /opt/scripts/file-backup.sh >> /var/log/file-backup.log 2>&1

# --- MAINTENANCE ---
# Clear temp files older than 7 days, daily at 3 AM
0 3 * * * /usr/bin/find /tmp -type f -mtime +7 -delete

# Rotate application logs every Sunday at 4 AM
0 4 * * 0 /opt/scripts/rotate-logs.sh >> /var/log/log-rotation.log 2>&1

# --- MONITORING ---
# Health check every 5 minutes
*/5 * * * * /opt/scripts/healthcheck.sh > /dev/null 2>&1

# SSL certificate expiry check daily at 6 AM
0 6 * * * /opt/scripts/check-ssl.sh

# Disk space alert if usage > 90%, every hour
0 * * * * /opt/scripts/disk-alert.sh

# --- REPORTS ---
# Send daily summary at 8 AM on weekdays
0 8 * * 1-5 /opt/scripts/daily-report.sh

# Monthly analytics report on the 1st at 9 AM
0 9 1 * * /opt/scripts/monthly-report.sh

7. Testing and Debugging Cron

Before deploying a cron job to production, verify that it does what you expect:

1
Use a Cron Expression Parser

Paste your expression into our Cron Expression Parser to see the next 10 run times and a human-readable explanation.

2
Check Cron Logs

On most Linux systems, cron logs appear in /var/log/syslog or /var/log/cron. Use grep CRON /var/log/syslog to filter.

3
Redirect Output

Capture stdout and stderr to a log file for debugging. This prevents cron from sending mail for every execution.

4
Test with Shorter Intervals

Before committing to a monthly schedule, test with * * * * * (every minute) to make sure the script runs correctly, then change to the target schedule.

5
Verify Mail Configuration

By default, cron emails output to the user. Set MAILTO="" at the top of your crontab to disable email, or set it to a real address for alerts.

# Redirect all output to a log file
0 2 * * * /path/to/backup.sh >> /var/log/cron-backup.log 2>&1

# Disable cron mail for this job
0 2 * * * /path/to/backup.sh > /dev/null 2>&1

# Set MAILTO at the top of crontab
MAILTO=""
# Or send to a real address
MAILTO="admin@example.com"

# Check cron logs on Debian/Ubuntu
grep CRON /var/log/syslog | tail -20

# Check cron logs on CentOS/RHEL
grep CRON /var/log/cron | tail -20

# On systems using journald (systemd)
journalctl -u cron --since "1 hour ago"

# Quick test: add a job that writes to a file
# Then check if the file gets updated
* * * * * echo "cron works: $(date)" >> /tmp/cron-test.log

# Verify your crontab was saved correctly
crontab -l | grep -v '^#'

# Check if cron daemon is running
systemctl status cron    # Debian/Ubuntu
systemctl status crond   # CentOS/RHEL

Common Cron Debugging Checklist

CheckHow to Verify
Cron daemon running?systemctl status cron (or crond)
Crontab saved?crontab -l and look for your entry
Script executable?chmod +x /path/to/script.sh
Full paths used?Use which python3 to find full path
Output captured?Add >> /tmp/debug.log 2>&1
Permissions correct?Script owner = crontab owner
No syntax errors?bash -n /path/to/script.sh
Timezone correct?timedatectl or date to check

Build and test your cron expressions interactively:

8. Frequently Asked Questions

What is the format of a cron expression?

A standard cron expression has 5 fields separated by spaces: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7). For example, "0 9 * * 1-5" means every weekday at 9:00 AM.

What does */5 mean in cron?

The */5 syntax means "every 5 units" for the given field. In the minute field, */5 * * * * runs every 5 minutes (at 0, 5, 10, 15, ... 55). In the hour field, 0 */5 * * * runs every 5 hours at minute 0.

How do I run a cron job every 30 seconds?

Standard cron does not support sub-minute intervals. The workaround is to create two cron entries: one for the top of the minute and one with a 30-second sleep: * * * * * /path/to/script.sh and * * * * * sleep 30 && /path/to/script.sh

What is the difference between cron and crontab?

Cron is the background daemon (service) that executes scheduled tasks. Crontab (cron table) is the file that lists the scheduled jobs and their timing. You use the "crontab" command to edit, list, or remove your personal cron table.

Can I use cron on Windows?

Native Windows does not have cron. The equivalent is Task Scheduler (schtasks.exe). However, if you use WSL (Windows Subsystem for Linux), you can use cron normally. Docker containers on Windows also support cron.

𝕏 Twitterin LinkedIn
บทความนี้มีประโยชน์ไหม?

อัปเดตข่าวสาร

รับเคล็ดลับการพัฒนาและเครื่องมือใหม่ทุกสัปดาห์

ไม่มีสแปม ยกเลิกได้ตลอดเวลา

ลองเครื่องมือที่เกี่ยวข้อง

Cron Expression GeneratorCron Expression Parser⏲️Crontab Generator🔍Cron Expression Parser

บทความที่เกี่ยวข้อง

ตัวสร้างและแยกวิเคราะห์ Cron Expression: ไวยากรณ์ ตัวอย่าง และโค้ด

เครื่องมือสร้างและแยกวิเคราะห์ Cron Expression ฟรี เรียนรู้ไวยากรณ์ Cron และตั้งเวลางานด้วย Node.js, Python และ Bash

การตรวจสอบ YAML Docker Compose: 10 ข้อผิดพลาดไวยากรณ์ที่พบบ่อยและวิธีแก้ไข

หยุดเสียเวลากับข้อผิดพลาด YAML Docker Compose เรียนรู้การระบุและแก้ไข 10 ข้อผิดพลาดที่พบบ่อยที่สุด