Cron Cheatsheet

The Ultimate Developer's Guide to Cron Jobs, Crontab Syntax & Scheduling

Interactive Tools Copy-Paste Ready Mobile Optimized

⚙️ Cron Syntax & Special Characters

Master the complete cron syntax with special characters and shortcuts:

Basic Syntax Structure

* * * * * command
minute hour day month weekday
Minute: 0-59
Hour: 0-23
Day: 1-31
Month: 1-12
Weekday: 0-6 (Sun-Sat)

Special Characters

* Any value
Matches any value in the field
, Value list separator
Example: 1,15,30 (1st, 15th, 30th)
- Range of values
Example: 1-5 (Monday to Friday)
/ Step values
Example: */5 (every 5 units)

Special Strings (Shortcuts)

Instead of the five fields, you can use these convenient shortcuts:

@reboot

Run once at system startup

@reboot /path/to/startup-script.sh
@yearly

Run once a year (same as @annually)

Equivalent: 0 0 1 1 *
@monthly

Run once a month

Equivalent: 0 0 1 * *
@weekly

Run once a week

Equivalent: 0 0 * * 0
@daily

Run once a day

Equivalent: 0 0 * * *
@hourly

Run once an hour

Equivalent: 0 * * * *

📋 Comprehensive Cron Examples

Copy-paste ready cron expressions for every scheduling need:

⏰ Time Intervals

Every Minute

* * * * * /path/to/command

Runs every minute of every day

Every 5 Minutes

*/5 * * * * /path/to/command

Runs every 5 minutes

Every 15 Minutes

*/15 * * * * /path/to/command

Runs every 15 minutes

Top of Every Hour

0 * * * * /path/to/command

Runs at the top of every hour

Every 5 Hours

0 */5 * * * /path/to/command

Runs every 5 hours

Daily at Midnight

0 0 * * * /path/to/command

Runs every day at midnight

💼 Business Hours & Weekdays

Weekdays at 5 PM

0 17 * * 1-5 /path/to/command

Runs Monday through Friday at 5:00 PM

Weekdays at 7:30 PM

30 19 * * 1-5 /path/to/command

Runs Monday through Friday at 7:30 PM

Sunday at 9:30 AM

30 9 * * 0 /path/to/command

Runs every Sunday at 9:30 AM

📅 Monthly & Special Cases

First Day of Month at 8 AM

0 8 1 * * /path/to/command

Runs on the 1st of every month at 8:00 AM

Last Day of Month at 6:15 PM

15 18 * * * [ "$(date +\%m -d tomorrow)" != "$(date +\%m)" ] && /path/to/command

Complex: runs on last day of every month at 6:15 PM

Daily Backup at 2:30 AM

30 2 * * * /path/to/backup_command

Backup the website every day at 2:30 AM

💡
Pro Tip:

Always include the full path to your script and consider redirecting output:

/full/path/to/script.sh >> /var/log/myscript.log 2>&1

🛠️ Interactive Cron Tools

Generate and validate cron expressions with our interactive tools:

🛠️ Interactive Cron Generator

* = every minute
* = every hour
* = every day
* = every month
0=Sun, 6=Sat

🔍 Cron Expression Explainer

✅ Real-time Cron Validator

Type to see real-time validation

🐛 Crontab Management & Troubleshooting

⚙️ Crontab Management Commands

Edit Cron Jobs

crontab -e

Opens your crontab file in the default editor

List Cron Jobs

crontab -l

Display all current cron jobs for the user

Remove All Cron Jobs

crontab -r

⚠️ Removes ALL cron jobs - use with caution!

Edit Another User's Crontab

sudo crontab -e -u username

Edit cron jobs for a specific user (requires sudo)

🚨 Most Common Issues

⚠️
Environment Variables Not Set

Cron runs with a minimal environment. Always use full paths and set required environment variables.

PATH=/usr/local/bin:/usr/bin:/bin
0 2 * * * /full/path/to/script.sh
⚠️
Timezone Issues

Cron uses the system timezone. To specify a different timezone:

CRON_TZ=America/New_York
0 9 * * * /path/to/script.sh

Best Practices

Test Your Commands

Always test commands in your terminal before adding to crontab to catch errors early.

Use Absolute Paths

Cron has limited environment variables. Always use full paths for commands and files.

Consider Time Zones

Be aware of Daylight Saving Time changes and use CRON_TZ when needed.

Use Lock Files

Prevent overlapping executions with flock or custom lock files for long-running jobs.

Monitor Your Jobs

Use monitoring tools like Cronitor or Healthchecks.io to track job execution.

Backup Your Crontab

Keep a copy under version control - there's no automatic backup!

🔍 Debugging Cron Jobs

Command Purpose
crontab -l List current user's cron jobs
crontab -e Edit current user's cron jobs
sudo crontab -l -u username List another user's cron jobs
grep CRON /var/log/syslog Check cron execution logs
systemctl status cron Check if cron service is running
📝
Best Practices for Logging

Always redirect output to capture both success and error messages:

0 2 * * * /path/to/script.sh >> /var/log/myscript.log 2>&1
  • >> appends stdout to log file
  • 2>&1 redirects stderr to stdout

Frequently Asked Questions

What's the difference between cron and crontab? +
Why isn't my cron job running? +
Can I run a cron job every second? +
How do I run a cron job as a different user? +
What happens if a cron job is still running when the next execution time arrives? +
How do I test a cron expression without waiting? +

🚀 Advanced Topics

🐳 Cron in Docker & Kubernetes

Docker:

# Dockerfile
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y cron
COPY crontab /etc/cron.d/mycron
RUN chmod 0644 /etc/cron.d/mycron
CMD ["cron", "-f"]
                            

Kubernetes CronJob:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: my-cronjob
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: my-container
            image: my-image
            command: ["/bin/sh", "-c", "echo Hello World"]
          restartPolicy: OnFailure
                            

⚙️ Systemd Timers vs Cron

Feature Cron Systemd Timers
Logging Manual setup required Integrated with journald
Dependencies Limited Full systemd dependency system
Resource limits No built-in support Built-in resource management
Flexibility Simple time-based Event-based triggers available

📥 Download Offline Reference

Get a PDF version of this cheatsheet for offline reference:

📅 Visual Timeline Preview

See exactly when your cron job will run in the next 24 hours:

🌍 Timezone Converter

Convert cron execution times between different timezones:

Source Timezone

Target Timezone

Real-time Cron Validator

Validate your cron expressions with instant feedback:

✅ Real-time Cron Validator

Type to see real-time validation

🔗 Platform Integration Examples

Ready-to-use cron configurations for popular platforms:

GH

GitHub Actions

on:
  schedule:
    - cron: '0 2 * * *'
jobs:
  backup:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Daily backup"
                            
AWS

AWS EventBridge

# Rate expression
rate(5 minutes)
rate(1 hour)
rate(1 day)

# Cron expression
cron(0 2 * * ? *)
cron(15 10 ? * 6L *)
                            
GCP

Google Cloud Scheduler

gcloud scheduler jobs create http my-job \
  --schedule="0 2 * * *" \
  --uri="https://myapp.com/cron" \
  --http-method=GET \
  --time-zone="America/New_York"
                            

🎯 Quick Reference Cards

Downloadable reference cards for common scenarios:

Time Intervals

Every minute, hour, day patterns

💼

Business Hours

Weekday and business hour patterns

🔧

Maintenance

Backup and maintenance schedules

🚨

Monitoring

Health checks and alerts