Ob Backups, Deployments oder Bereinigungsskripte — cron ist das Rückgrat der Aufgabenplanung auf Unix/Linux. Dieses Cheat Sheet bietet 50+ kopierbare Cron-Ausdruck-Beispiele nach Häufigkeit sortiert.
1. Cron-Ausdruck-Syntax
Ein Standard-Cron-Ausdruck besteht aus 5 Feldern:
┌───────────── Minute (0–59)
│ ┌─────────── Stunde (0–23)
│ │ ┌───────── Tag des Monats (1–31)
│ │ │ ┌─────── Monat (1–12)
│ │ │ │ ┌───── Wochentag (0–7)
│ │ │ │ │
* * * * * command_to_executeDer Befehl folgt den fünf Feldern. Nutzen Sie unseren Cron-Generator.
2. Sonderzeichen
Cron verwendet vier Sonderzeichen:
| Zeichen | Bedeutung | Beispiel | Beschreibung |
|---|---|---|---|
| * | Entspricht jedem möglichen Wert | * * * * * | Every minute |
| , | Gibt eine Liste an | 0 9 * * 1,3,5 | Mon, Wed, Fri at 9 AM |
| - | Definiert einen Bereich | 0 9 * * 1-5 | Mon through Fri at 9 AM |
| / | Definiert ein Schrittintervall | */10 * * * * | Every 10 minutes |
3. 50+ Cron-Ausdruck-Beispiele
Die folgenden Tabellen decken die häufigsten Cron-Zeitpläne ab.
Alle X Minuten
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| * * * * * | Every minute | 10:00, 10:01, 10:02 ... |
| */1 * * * * | Every minute (explicit) | 10:00, 10:01, 10:02 ... |
| */2 * * * * | Every 2 minutes | 10:00, 10:02, 10:04 ... |
| */5 * * * * | Every 5 minutes | 10:00, 10:05, 10:10 ... |
| */10 * * * * | Every 10 minutes | 10:00, 10:10, 10:20 ... |
| */15 * * * * | Every 15 minutes | 10:00, 10:15, 10:30, 10:45 |
| */20 * * * * | Every 20 minutes | 10:00, 10:20, 10:40 ... |
| */30 * * * * | Every 30 minutes | 10:00, 10:30, 11:00 ... |
| 0,15,30,45 * * * * | At 0, 15, 30, 45 minutes past each hour | 10:00, 10:15, 10:30, 10:45 |
Stündliche Zeitpläne
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 * * * * | Every hour (at minute 0) | 10:00, 11:00, 12:00 ... |
| 30 * * * * | Every hour at minute 30 | 10:30, 11:30, 12:30 ... |
| 15 * * * * | Every hour at minute 15 | 10:15, 11:15, 12:15 ... |
| 0 */2 * * * | Every 2 hours | 00:00, 02:00, 04:00 ... |
| 0 */3 * * * | Every 3 hours | 00:00, 03:00, 06:00 ... |
| 0 */4 * * * | Every 4 hours | 00:00, 04:00, 08:00 ... |
| 0 */6 * * * | Every 6 hours | 00:00, 06:00, 12:00, 18:00 |
| 0 */8 * * * | Every 8 hours | 00:00, 08:00, 16:00 |
| 0 */12 * * * | Every 12 hours | 00:00, 12:00 |
Tägliche Zeitpläne
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 0 * * * | Daily at midnight (00:00) | Tomorrow 00:00 |
| 0 1 * * * | Daily at 1:00 AM | Tomorrow 01:00 |
| 0 6 * * * | Daily at 6:00 AM | Tomorrow 06:00 |
| 30 7 * * * | Daily at 7:30 AM | Tomorrow 07:30 |
| 0 9 * * * | Daily at 9:00 AM | Tomorrow 09:00 |
| 30 8 * * * | Daily at 8:30 AM | Tomorrow 08:30 |
| 0 12 * * * | Daily at noon (12:00) | Tomorrow 12:00 |
| 0 15 * * * | Daily at 3:00 PM | Tomorrow 15:00 |
| 0 18 * * * | Daily at 6:00 PM | Tomorrow 18:00 |
| 0 23 * * * | Daily at 11:00 PM | Tomorrow 23:00 |
| 0 8-17 * * * | Every hour from 8 AM to 5 PM | 08:00, 09:00 ... 17:00 |
| 0 9,12,18 * * * | Three times a day (9 AM, noon, 6 PM) | 09:00, 12:00, 18:00 |
Wöchentliche Zeitpläne
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 9 * * 1 | Every Monday at 9:00 AM | Next Monday 09:00 |
| 0 9 * * 1-5 | Weekdays (Mon-Fri) at 9:00 AM | Next weekday 09:00 |
| 0 0 * * 0 | Every Sunday at midnight | Next Sunday 00:00 |
| 0 0 * * 6,0 | Saturday & Sunday at midnight | Next Sat/Sun 00:00 |
| 0 17 * * 5 | Every Friday at 5:00 PM | Next Friday 17:00 |
| 0 9 * * 1,3,5 | Mon, Wed, Fri at 9:00 AM | Next Mon/Wed/Fri 09:00 |
| 0 8-17 * * 1-5 | Hourly 8AM–5PM, weekdays only | Next weekday 08:00 |
| 30 6 * * 1-5 | Weekdays at 6:30 AM | Next weekday 06:30 |
Monatliche Zeitpläne
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 0 1 * * | 1st of every month at midnight | Next month, 1st 00:00 |
| 0 0 15 * * | 15th of every month at midnight | Next 15th 00:00 |
| 0 9 1 * * | 1st of every month at 9:00 AM | Next month, 1st 09:00 |
| 0 0 1,15 * * | 1st and 15th at midnight | Next 1st or 15th 00:00 |
| 0 0 * * 5L | Last Friday of the month (non-std) | Last Fri 00:00 |
| 0 9 * * 1#1 | First Monday of the month (non-std) | First Mon 09:00 |
| 0 0 28 * * | 28th of every month at midnight | Next 28th 00:00 |
Jährliche / Quartalszeitpläne
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 0 1 1 * | January 1st at midnight | Jan 1 00:00 |
| 0 0 1 1,4,7,10 * | Quarterly: Jan, Apr, Jul, Oct 1st | Next quarter 00:00 |
| 0 0 1 1,7 * | Bi-annually: Jan 1 & Jul 1 | Jan 1 or Jul 1 00:00 |
| 0 0 25 12 * | December 25th at midnight | Dec 25 00:00 |
| 0 0 1 */3 * | Every 3 months on the 1st | Next 1st in 3 months |
| 0 0 1 */6 * | Every 6 months on the 1st | Next 1st in 6 months |
Business & DevOps
| Ausdruck | Beschreibung | Nächste Ausführung |
|---|---|---|
| 0 2 * * * | Database backup at 2:00 AM daily | Tomorrow 02:00 |
| 0 3 * * 0 | Log rotation every Sunday at 3 AM | Next Sunday 03:00 |
| 0 4 1 * * | Monthly DB cleanup on 1st at 4 AM | Next month, 1st 04:00 |
| 0 1 * * * | SSL cert check daily at 1 AM | Tomorrow 01:00 |
| */5 * * * * | Health check every 5 minutes | 10:00, 10:05, 10:10 ... |
| 0 5 * * 1-5 | Deploy window: weekdays at 5 AM | Next weekday 05:00 |
| 0 0 * * * | Rotate logs daily at midnight | Tomorrow 00:00 |
| 0 */4 * * * | Send report digest every 4 hours | 00:00, 04:00, 08:00 ... |
| 0 22 * * 5 | Friday night maintenance at 10 PM | Next Friday 22:00 |
| 30 2 * * * | Temp file cleanup at 2:30 AM daily | Tomorrow 02:30 |
4. Crontab-Befehle
Der crontab-Befehl verwaltet Cron-Dateien:
| Befehl | Funktion |
|---|---|
| crontab -e | Edit your crontab file (opens in default editor) |
| crontab -l | List all cron jobs for the current user |
| crontab -r | Remove all cron jobs for the current user (use with caution!) |
| crontab -u alice -l | List cron jobs for a specific user (requires root) |
| crontab -u alice -e | Edit crontab for a specific user (requires root) |
| crontab filename | Install 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 -r5. Plattformspezifische Syntax
Die Cron-Syntax variiert je nach Plattform:
5 Felder. Das Standard-Format.
# Standard 5-field crontab
*/5 * * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&15 Felder in schedule.cron. Immer UTC.
# .github/workflows/scheduled.yml
on:
schedule:
- cron: '0 9 * * 1-5' # Weekdays 9AM UTC6 Felder. Verwendet ?.
# AWS EventBridge (6 fields, note the ?)
cron(0 9 ? * MON-FRI *) # Weekdays 9AM UTC5 Standard-Felder. Timezone ab K8s 1.27+.
# Kubernetes CronJob spec
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-backup
spec:
schedule: "0 2 * * *"
timeZone: "America/New_York" # K8s 1.27+5 Felder in vercel.json. UTC.
// vercel.json
{
"crons": [{
"path": "/api/cron/daily-report",
"schedule": "0 9 * * *"
}]
}6. Häufige Fallstricke
Die häufigsten Fehler bei Cron:
Cron nutzt die Systemzeitzone. CI/CD-Plattformen nutzen UTC.
Nutzen Sie flock oder eine Lock-Datei.
Nutzen Sie UTC um Probleme zu vermeiden.
Wenn beide gesetzt sind, läuft der Job bei einem von beiden.
Mindestauflösung: 1 Minute. Für Sub-Minute nutzen Sie sleep.
Cron-Jobs laufen mit minimaler Umgebung. Verwenden Sie vollständige Pfade.
# 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.sh7. Testen und Debuggen
Vor dem Produktiv-Deployment:
Nutzen Sie unseren Cron-Ausdruck-Parser.
Prüfen Sie /var/log/syslog oder /var/log/cron.
Erfassen Sie stdout/stderr in einer Logdatei.
Testen Sie zuerst mit * * * * *.
Setzen Sie MAILTO="" zum Deaktivieren.
# 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/RHELCommon Cron Debugging Checklist
| Check | How 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 |
Erstellen und testen Sie Ihre Cron-Ausdrücke:
8. Häufig gestellte Fragen
Was ist das Format eines Cron-Ausdrucks?
Ein Standard-Cron-Ausdruck hat 5 Felder: Minute (0-59), Stunde (0-23), Tag (1-31), Monat (1-12) und Wochentag (0-7).
Was bedeutet */5 in Cron?
*/5 bedeutet "alle 5 Einheiten". Im Minutenfeld läuft */5 * * * * alle 5 Minuten.
Wie führe ich einen Cron-Job alle 30 Sekunden aus?
Standard-Cron unterstützt keine Sub-Minuten-Intervalle. Erstellen Sie zwei Einträge mit sleep 30.
Was ist der Unterschied zwischen cron und crontab?
Cron ist der Daemon. Crontab ist die Datei mit den geplanten Jobs.
Kann ich cron unter Windows verwenden?
Natives Windows hat kein cron. Die Alternative ist der Aufgabenplaner. Mit WSL können Sie cron normal nutzen.