Platforms

Cron in Linux

Linux cron runs commands on a recurring schedule. It is commonly edited with crontab and is available on most Unix-like systems.

Crontab basics

crontab -e   # edit your user crontab
crontab -l   # list installed cron entries
crontab -r   # remove the current user crontab

Environment and logs

Cron jobs often run with a smaller environment than your interactive shell. Set PATH, use absolute paths, and redirect output to logs.

PATH=/usr/local/bin:/usr/bin:/bin
0 9 * * 1-5 /usr/local/bin/report.sh >> /var/log/report.log 2>&1

Production cautions

  • Check file permissions for scripts and log files.
  • Avoid commands that require interactive input.
  • Use locks for long-running jobs.

Common mistakes

  • Assuming shell aliases work in cron.
  • Forgetting executable permissions on scripts.
  • Not redirecting stderr, so failures disappear.

FAQ

How do I edit a Linux cron job?

Run crontab -e for the current user, then add or update a 5-field cron entry.

Where are cron logs stored?

It depends on the distribution. Check system logs such as /var/log/syslog, /var/log/cron, or journalctl.