August 25, 2026 · by Alex M.
Managing a server means dealing with the same tasks over and over: nightly database backups, cleaning up temp files, sending performance reports, updating records. Done manually, these tasks eat up time and invite human error. The solution has been built into Linux since the beginning — it's called cron, a background task scheduler available on every Linux distribution.
In this guide, you'll learn step by step how to configure cron jobs on a Linux VPS — from basic syntax to advanced examples, output logging, and troubleshooting.
Cron is a daemon (background service) that runs continuously and checks whether any scheduled tasks need to be executed. Tasks are defined in special files called crontab (cron table).
Every Linux user can have their own crontab, and the system also maintains a global one at /etc/crontab. The cron daemon reads these files and runs the specified commands at the scheduled times.
systemctl status cron # Debian/Ubuntu
systemctl status crond # CentOS/AlmaLinux/Rocky
If the service isn't active, enable and start it:
systemctl enable --now cron
Each line in a crontab follows this format:
* * * * * /path/to/command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, where 0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)
| Operator | Meaning | Example |
|---|---|---|
* |
Any value | * * * * * = every minute |
, |
List of values | 0 9,18 * * * = at 09:00 and 18:00 |
- |
Range | 0 9-17 * * * = every hour between 9 and 17 |
/ |
Step | */15 * * * * = every 15 minutes |
To edit the current user's crontab:
crontab -e
To list existing jobs:
crontab -l
To edit another user's crontab (as root):
crontab -u www-data -e
Tip: On first run, you'll be asked to choose an editor. Pick
nanoif you're new to the terminal — it's friendlier thanvim.
0 2 * * * /usr/bin/mysqldump -u root -pYOUR_PASSWORD database_name > /backup/db_$(date +\%Y\%m\%d).sql
Runs every night at 02:00, saving a full database dump. On an NVMe VPS, fast I/O speeds keep backup windows short even for large databases.
0 3 * * 0 /usr/bin/find /tmp -type f -mtime +7 -delete
Runs every Sunday at 03:00 and deletes files in /tmp older than 7 days.
0 0 1 * * /usr/bin/certbot renew --quiet && systemctl reload nginx
Checks and renews SSL certificates on the first day of every month. Essential if you're using Let's Encrypt.
0 8 * * * /usr/bin/df -h | /usr/bin/mail -s "Disk report $(hostname)" [email protected]
*/5 * * * * /usr/bin/php /var/www/html/wp-cron.php > /dev/null 2>&1
WordPress has a built-in pseudo-cron that fires on page visits. For reliability — especially on a WordPress hosting plan with variable traffic — it's better to disable WP-Cron and use the system cron instead.
Cron runs with a minimal environment and does not inherit the user's shell variables. That's why you must always use absolute paths for commands.
You can define global variables at the top of your crontab:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
[email protected]
MAILTO — the email address to receive command output (set to "" to suppress emails entirely).PATH — the directories cron will search for executables.By default, cron sends command output via email (if sendmail is configured). A cleaner approach is redirecting output to log files:
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
>> appends output to the file (doesn't overwrite).2>&1 redirects errors to the same file.To prevent log files from growing indefinitely, pair cron with logrotate — another essential tool in the Linux server management toolkit.
Beyond user crontabs, Linux provides predefined directories for system tasks:
| Directory | Frequency |
|---|---|
/etc/cron.hourly/ |
Hourly |
/etc/cron.daily/ |
Daily |
/etc/cron.weekly/ |
Weekly |
/etc/cron.monthly/ |
Monthly |
To add a script for daily execution, drop it into /etc/cron.daily/ and make it executable:
chmod +x /etc/cron.daily/myscript.sh
Files in /etc/cron.d/ support full crontab syntax including the username field:
0 4 * * * root /usr/local/bin/cleanup.sh
A misconfigured cron job can become a security liability. Key best practices:
chmod 777 script is a risk.bash
chmod 700 /usr/local/bin/backup.sh
chown root:root /usr/local/bin/backup.sh~/.my.cnf for MySQL)./etc/cron.allow and /etc/cron.deny.bash
grep CRON /var/log/syslog # Ubuntu/Debian
grep CRON /var/log/cron # CentOS/AlmaLinuxOn a managed dedicated server, our team handles these configurations for you.
If a cron job fails silently, work through this checklist:
chmod +x script.sh).source ~/.bashrc at the top of your script, or define PATH in crontab.crontab -l and test the command manually in the terminal.systemctl status cron.# Quick test: run the command as the cron user manually
su -s /bin/bash www-data -c "/usr/bin/php /var/www/html/script.php"
Modern Linux systems (Ubuntu 20.04+, AlmaLinux 8+) offer systemd timers as a more powerful alternative to cron. They support:
For most common use cases, however, cron remains simple, portable, and perfectly adequate. You can read more about advanced automation options on the CLIQHOST blog.
Cron jobs are a fundamental skill for any server administrator. With the right configuration, you can automate backups, maintenance, reporting, and much more — eliminating human error and saving hours of repetitive work.
For reliable execution of automated tasks, you need a stable and fast foundation. CLIQHOST NVMe VPS plans provide dedicated resources, high I/O throughput, and full root access — everything you need to run cron jobs confidently. Need help with server configuration? Explore our server management services or get in touch with our team — we're ready to help.
Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.
"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."
"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."
"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."