⚙️ Cron Syntax & Special Characters
Master the complete cron syntax with special characters and shortcuts:
Basic Syntax Structure
Special Characters
*
Any value
,
Value list separator
-
Range of values
/
Step values
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
Runs every minute of every day
Every 5 Minutes
Runs every 5 minutes
Every 15 Minutes
Runs every 15 minutes
Top of Every Hour
Runs at the top of every hour
Every 5 Hours
Runs every 5 hours
Daily at Midnight
Runs every day at midnight
💼 Business Hours & Weekdays
Weekdays at 5 PM
Runs Monday through Friday at 5:00 PM
Weekdays at 7:30 PM
Runs Monday through Friday at 7:30 PM
Sunday at 9:30 AM
Runs every Sunday at 9:30 AM
📅 Monthly & Special Cases
First Day of Month at 8 AM
Runs on the 1st of every month at 8:00 AM
Last Day of Month at 6:15 PM
Complex: runs on last day of every month at 6:15 PM
Daily Backup at 2:30 AM
Backup the website every day at 2:30 AM
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
🔍 Cron Expression Explainer
✅ Real-time Cron Validator
🐛 Crontab Management & Troubleshooting
⚙️ Crontab Management Commands
Edit Cron Jobs
Opens your crontab file in the default editor
List Cron Jobs
Display all current cron jobs for the user
Remove All Cron Jobs
⚠️ Removes ALL cron jobs - use with caution!
Edit Another User's Crontab
Edit cron jobs for a specific user (requires sudo)
🚨 Most Common Issues
Cron runs with a minimal environment. Always use full paths and set required environment variables.
0 2 * * * /full/path/to/script.sh
Cron uses the system timezone. To specify a different timezone:
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 |
Always redirect output to capture both success and error messages:
>>
appends stdout to log file2>&1
redirects stderr to stdout
❓ Frequently Asked Questions
🚀 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:
Next 10 Executions:
🌍 Timezone Converter
Convert cron execution times between different timezones:
Source Timezone
Target Timezone
Conversion Result:
✅ Real-time Cron Validator
Validate your cron expressions with instant feedback:
✅ Real-time Cron Validator
🔗 Platform Integration Examples
Ready-to-use cron configurations for popular platforms:
GitHub Actions
on: schedule: - cron: '0 2 * * *' jobs: backup: runs-on: ubuntu-latest steps: - run: echo "Daily backup"
AWS EventBridge
# Rate expression rate(5 minutes) rate(1 hour) rate(1 day) # Cron expression cron(0 2 * * ? *) cron(15 10 ? * 6L *)
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