Home › Cron Jobs in Ubuntu
Cron Jobs in Ubuntu
How to create, list, edit and debug cron jobs on Ubuntu. Includes log locations, systemd timer alternatives and Ubuntu-specific gotchas.
Create a Cron Job on Ubuntu
Ubuntu uses the standard cron daemon (cron package, installed by default). See the Ubuntu crontab(5) man page for the full 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.
Essential Ubuntu Crontab Commands
| Command | What it does |
|---|---|
crontab -e | Edit your crontab |
crontab -l | List all your cron jobs |
crontab -r | Delete all your cron jobs (no confirmation) |
sudo crontab -u www-data -e | Edit the crontab for the www-data user (common for web server jobs) |
sudo crontab -e | Edit root's crontab |
systemctl status cron | Check if the cron daemon is running |
sudo systemctl restart cron | Restart 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.
View cron activity
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.
Add a Cron Job 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.
Generate the cron expression for your Ubuntu job
Build the schedule visually, copy the expression and paste it in your crontab.