Crontab Syntax Errors — Common Mistakes and Debugging Cron Jobs
Warningsystem
Overview
Fix crontab syntax errors and debug cron jobs that do not run, including environment differences, path issues, output handling, and timing format mistakes.
Key Details
- Crontab format: minute hour day-of-month month day-of-week command
- Cron runs commands in a minimal environment — no user .bashrc, different PATH
- Output goes to the user's local mail unless redirected (>/dev/null 2>&1 to suppress)
- Cron logs usually in /var/log/cron or via journalctl -u cron
- Common pitfall: using % in crontab without escaping (% means newline in crontab)
Common Causes
- Incorrect time format (using 24-hour clock wrong, confusing minute and hour fields)
- Missing full paths to commands (cron PATH is minimal: /usr/bin:/bin)
- Unescaped % character in the command line
- Script lacking execute permission or missing shebang (#!/bin/bash)
- Environment variables not set (HOME, PATH, LANG differ from interactive shell)
Steps
- 1Edit crontab: crontab -e (user) or sudo crontab -e (root)
- 2Use full paths for all commands: /usr/bin/python3 instead of just python3
- 3Set PATH at the top of crontab: PATH=/usr/local/bin:/usr/bin:/bin
- 4Escape % characters: use \% instead of % in crontab command lines
- 5Redirect output for debugging: * * * * * /path/script.sh >> /tmp/cron.log 2>&1
- 6Verify timing with crontab.guru website to check your schedule expression
Tags
crontabcronschedulingsyntaxautomation
Related Items
More in System
windows-C000021A-status-system-process-terminatedWindows Error 0xC000021A — STATUS SYSTEM PROCESS TERMINATED
Criticalwindows-C0000225-boot-configuration-errorWindows Error 0xC0000225 — Boot Configuration Error
Criticalwindows-C000000F-boot-selection-failedWindows Error 0xC000000F — Boot Selection Failed
Criticalwindows-80004005-unspecified-errorWindows Error 0x80004005 — Unspecified Error
Warningwindows-80070570-file-or-directory-corruptedWindows Error 0x80070570 — File or Directory Corrupted
Errorwindows-system-0xc0000185Windows Error 0xC0000185 — Boot Device Inaccessible
CriticalFrequently Asked Questions
Cron runs with a minimal environment. The most common issue is PATH: your interactive shell has a richer PATH. Use full paths to all commands in crontab entries.