Backups at 2 am, log rotation, cache clearing, certificate renewals, health checks — a well-run server does its chores automatically. Cron is the scheduler that has done this job on Unix systems for decades, and on Ubuntu 24.04 it is installed, running, and waiting for your instructions. This guide covers crontab syntax (with a cheat sheet), real examples, and the classic mistakes that make cron jobs silently fail.
Your crontab
crontab -e # edit your user's crontab (picks nano by default) crontab -l # list current entries sudo crontab -e # root's crontab — for system-level jobs
The five fields
┌──────── minute (0–59) │ ┌────── hour (0–23) │ │ ┌──── day of month (1–31) │ │ │ ┌── month (1–12) │ │ │ │ ┌ day of week (0–7, 0 and 7 = Sunday) │ │ │ │ │ * * * * * command-to-run
Special characters: * every, */5 every 5, 1,15 lists, 9-17 ranges. Common recipes:
0 3 * * * daily at 03:00 */10 * * * * every 10 minutes 0 */6 * * * every 6 hours 0 4 * * 0 Sundays at 04:00 0 0 1 * * first day of each month @reboot once, at every boot @daily shorthand for 0 0 * * *
Real-world examples
crontab -e
# Daily database backup at 02:30, with logging 30 2 * * * /home/deploy/scripts/backup-db.sh >> /var/log/backup.log 2>&1 # Weekly cache clear 0 4 * * 0 /usr/bin/php /var/www/app/artisan cache:clear # Health-check ping every 5 minutes */5 * * * * /usr/bin/curl -fsS https://hc-ping.com/your-uuid > /dev/null
Why is my cron job not running? The big four
1. PATH is minimal. Cron runs with PATH=/usr/bin:/bin — use absolute paths for every command (/usr/bin/php, not php), or set PATH= at the top of the crontab.
2. Output vanished. Cron discards output unless you redirect it — always append >> /path/to/log 2>&1 while debugging.
3. Percent signs. % is special in crontab — escape as \% (bites everyone using date +\%F in backup filenames).
4. Script not executable. chmod +x script.sh, and give it a shebang line.
Did it actually run?
grep CRON /var/log/syslog | tail
Every execution is logged. If the entry appears here but the work did not happen, the bug is inside your script — check the log file you redirected to.
System-wide locations
Packages drop scheduled work into /etc/cron.daily/, /etc/cron.weekly/ and /etc/cron.d/ — that is how unattended upgrades and log rotation run. Put your own system jobs in /etc/cron.d/ with a sixth field naming the user:
# /etc/cron.d/myapp-backup 30 2 * * * deploy /home/deploy/scripts/backup-db.sh
flock: flock -n /tmp/backup.lock /path/to/backup.sh.Related Ubuntu guides
- How to Update Ubuntu Server: apt, Security Patches and Unattended Upgrades
- How to Manage Users and Groups on Ubuntu Server
- How to Check and Free Up Disk Space on Ubuntu Server
- How to Manage Services on Ubuntu with systemctl: The Complete systemd Guide
Prefer to have experts handle it?
LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.