Guides/Server Setup
Server Setup6 min read

How to Set Up and Manage Cron Jobs on Linux

Cron is the standard Linux scheduler for running commands at set intervals. This guide covers crontab syntax, common schedules, best practices for reliable cron jobs, and debugging when they fail.

Crontab Syntax

Each cron job line has 5 time fields followed by the command: minute hour day-of-month month day-of-week command. Fields: minute (0-59), hour (0-23), day (1-31), month (1-12), weekday (0-7, 0 and 7 are Sunday). Use * for "every". Examples: 0 2 * * * = 2am every day. */5 * * * * = every 5 minutes. 0 9 * * 1 = 9am every Monday. 0 0 1 * * = midnight on the first of every month.

Edit and List Cron Jobs

Edit your crontab: crontab -e (opens in your default editor). List current jobs: crontab -l. Remove all jobs: crontab -r (destructive — be careful). Edit another user's crontab: sudo crontab -u ubuntu -e. System-wide cron jobs live in /etc/cron.d/ (files), /etc/cron.daily/, /etc/cron.hourly/, /etc/cron.weekly/, /etc/cron.monthly/ (directories — drop scripts in, cron runs them at the appropriate interval).

Redirect Output to a Log File

By default, cron emails output to the local system mailbox which nobody reads. Redirect output: 0 2 * * * /home/ubuntu/backup.sh >> /home/ubuntu/cron.log 2>&1. The >> appends to the log, 2>&1 captures both stdout and stderr. For quiet jobs: command > /dev/null 2>&1 (discard all output). Use logrotate to rotate cron logs: create /etc/logrotate.d/myapp with: /home/ubuntu/cron.log { rotate 7 daily compress missingok notifempty }.

Use Absolute Paths in Cron Jobs

Cron runs with a minimal environment — $PATH does not include /usr/local/bin where npm, python3, and other tools usually live. Always use absolute paths: /usr/bin/python3 instead of python3, /usr/local/bin/node instead of node. Find absolute paths with: which python3, which node. Alternatively, source your bash profile at the start of your cron script: #!/bin/bash — source /home/ubuntu/.bashrc.

Debugging Failed Cron Jobs

If a cron job is not running: check cron is active: systemctl status cron. Check the system log for cron errors: grep CRON /var/log/syslog. Run the command manually as the cron user to check for errors. Verify file permissions: the script must be executable (chmod +x). Check if the script path is correct. Test your crontab syntax at crontab.guru. Add set -x to your script to enable debug output.

Need Help?

Want this done for you?

Our engineering team handles implementations like this every week. Get a free scoping call — we will tell you exactly what it takes and what it costs.

Book a free call

© 2026 NexWorldTech — Built for Global Dominance.