Error Codes Wiki

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

  1. 1Edit crontab: crontab -e (user) or sudo crontab -e (root)
  2. 2Use full paths for all commands: /usr/bin/python3 instead of just python3
  3. 3Set PATH at the top of crontab: PATH=/usr/local/bin:/usr/bin:/bin
  4. 4Escape % characters: use \% instead of % in crontab command lines
  5. 5Redirect output for debugging: * * * * * /path/script.sh >> /tmp/cron.log 2>&1
  6. 6Verify timing with crontab.guru website to check your schedule expression

Tags

crontabcronschedulingsyntaxautomation

Related Items

More in System

Frequently 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.