Home › Ubuntu Cron Jobs

Ubuntu Cron Jobs: Create, List, Log and Debug

How to add a cron job on Ubuntu, list and edit the crontab, find the cron log and debug a job that is not running. Covers Ubuntu 20.04, 22.04 and 24.04 LTS on both desktop and server.

How to Add a Cron Job on Ubuntu

Ubuntu includes cron by default. See the Ubuntu crontab(5) man page for the full syntax reference. Open your crontab with:

crontab -e

The first time you run this, Ubuntu asks which editor to use. Choose nano if you are not sure - it is the easiest. Your choice is saved and used for all future crontab -e calls.

Add your job at the bottom of the file, one job per line:

0 2 * * * /usr/bin/php /var/www/html/backup.php >> /var/log/backup.log 2>&1

Save and exit. Cron picks up the change immediately - no restart needed.

How to Restart Cron on Ubuntu

You rarely need to restart cron - it picks up crontab changes automatically. But if the cron daemon is not running or behaving unexpectedly, use these commands:

Check cron status

systemctl status cron

Shows whether the daemon is running, the last few log lines and any errors.

Start, stop and restart

sudo systemctl start cron
sudo systemctl stop cron
sudo systemctl restart cron

Enable on boot

sudo systemctl enable cron

On a fresh Ubuntu Server install, cron is usually enabled by default. On minimal or Docker images it may not be.

Install cron if missing

sudo apt update && sudo apt install cron
sudo systemctl enable cron
sudo systemctl start cron

Essential Ubuntu Crontab Commands

CommandWhat it does
crontab -eEdit your crontab
crontab -lList all your cron jobs
crontab -rDelete all your cron jobs (no confirmation)
sudo crontab -u www-data -eEdit the crontab for the www-data user (common for web server jobs)
sudo crontab -eEdit root's crontab
systemctl status cronCheck if the cron daemon is running
sudo systemctl restart cronRestart the cron daemon

Ubuntu Cron Log Location

Ubuntu logs cron activity to /var/log/syslog. This tells you when cron fires a job, but not what the job outputs. On Ubuntu 20.04, 22.04 and 24.04 the location is the same.

View Ubuntu cron log

grep CRON /var/log/syslog
# live:
tail -f /var/log/syslog | grep CRON

Log your job's output

0 2 * * * /path/script.sh >> /var/log/myjob.log 2>&1

Without this, you only see that cron ran the job - not whether it succeeded or failed.

Ubuntu 20.04+ with journald

journalctl -u cron --since "1 hour ago"
journalctl -u cron -f   # follow live

On newer Ubuntu versions, logs may go to journald instead of syslog depending on your configuration.

Ubuntu crontab log - what each line means

A typical syslog line looks like:

Jun 19 02:00:01 hostname CRON[12345]: (user) CMD (/usr/bin/php backup.php)

CMD means the job fired. If you see CRON[...]: (user) CMD but your script did nothing, the problem is inside the script - not in cron itself.

Cron Jobs on Ubuntu Server

Ubuntu Server works exactly the same as desktop for cron. The difference is you are likely connecting via SSH and running as a specific user. A few things worth keeping in mind on a server:

Run as the right user

A job added to your user's crontab runs as your user. If the script needs to write to /var/www, check that your user has permission to do so. For web server scripts, consider running as www-data: sudo crontab -u www-data -e

System-wide jobs

For jobs that should run regardless of which users are logged in, use /etc/crontab or drop a file in /etc/cron.d/. These require a username field:

0 2 * * * root /usr/bin/backup.sh

Debugging Cron Jobs on Ubuntu

Job not appearing in logs

If grep CRON /var/log/syslog shows nothing for your job, either the expression is wrong or the cron daemon is not running. Run systemctl status cron and validate your expression with the Cron Checker.

Job appears in logs but fails

The job ran but the script crashed. Add >> /tmp/crontest.log 2>&1 to capture output. Most common cause: missing PATH. Run the command manually first using its full path.

Check crontab format

Ubuntu's cron is strict about format. Make sure there is a newline at the end of your crontab file. A crontab with no trailing newline will silently ignore the last entry on some systems.

For a complete step-by-step diagnosis covering PATH, permissions, env vars and timezone:

Cron Job Not Running - Full Guide

Generate the cron expression for your Ubuntu job

Build the schedule visually, copy the expression and paste it in your crontab.