Set MAILTO and PATH at the top

Cron has a minimal PATH. Set PATH and MAILTO at the top, or jobs fail silently

crontab - <<'EOF' MAILTO=ops@example.com PATH=/usr/local/bin:/usr/bin:/bin 0 3 * * * backup.sh EOF

tool
cron8 commands
tags
crontroubleshootingsecrets

More cron commands

  • run-parts --test /etc/cron.daily

    List the scripts that would run, without running them. Handy for debugging cron.daily

  • systemd-run --on-calendar='*-*-* 03:00:00' --unit=backup /opt/backup.sh

    A transient OnCalendar timer with logs in journald, instead of a crontab line. Note: it is gone after reboot

  • at now + 1 hour <<< 'systemctl restart nginx'

    Schedule one delayed command. See the queue with atq, cancel with atrm

  • batch <<< '/opt/heavy-reindex.sh'

    Runs only when the load average drops below 1.5. Note: atd must be running

  • crontab -l -u <name> 2>/dev/null || echo 'no crontab'

    Check the jobs of a service account. Note: -u needs root or sudo

all 8 cron commands