What Is Cron? How to Set Up a Cron Job on Linux
What is cron and how do you use it? Crontab syntax, schedule examples, backup and restart jobs, common mistakes, cron logs and systemd timers on Linux.

Contents
Cron is the scheduler that automatically runs commands and scripts at set times on Linux servers. Jobs such as taking a backup every night, restarting a game server every morning, cleaning up old log files or checking a site regularly are defined once, and cron takes care of the rest. These tasks scheduled with cron are called cron jobs.
This guide covers crontab syntax, common schedule examples, practical jobs, cron's most annoying mistakes and systemd timers as an alternative.
How to edit the crontab
Each user has their own list of jobs, called the crontab. To edit it:
crontab -e
On the first run you're asked to choose a text editor; nano is the easiest. Use crontab -l to see your existing jobs. For jobs that need root privileges, edit root's crontab with sudo crontab -e.
Crontab syntax
Each line is one job and consists of five time fields followed by the command to run:
┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12)
│ │ │ │ ┌─ day of week (0–7, 0 and 7 are Sunday)
│ │ │ │ │
* * * * * command
| Symbol | Meaning | Example |
|---|---|---|
* | Every value | * in the hour field: every hour |
, | List | 1,15 the 1st and 15th of the month |
- | Range | 1-5 Monday to Friday |
/ | Step | */10 in the minute field: every 10 minutes |
Common schedule examples
| Schedule | Meaning |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | At the top of every hour |
30 3 * * * | Every day at 03:30 |
0 6 * * 1 | Every Monday at 06:00 |
0 0 1 * * | At midnight on the 1st of every month |
0 9-18 * * 1-5 | Every hour on the hour, 09:00–18:00 on weekdays |
@reboot | Once, every time the server boots |
@daily | Every day at midnight |
If you're not sure when an expression will run, you can type it into a site such as crontab.guru to see what it means.
Practical cron jobs
A database backup every night:
0 4 * * * /root/backup.sh >> /var/log/backup.log 2>&1
We cover taking regular backups that are independent of the server in detail in our Server backups guide.
Restarting a game server every morning:
0 6 * * * systemctl restart minecraft
Some game servers that stay up for a long time use more memory over time; a daily restart at the hour with the fewest players prevents this. This example assumes the game server runs as a systemd service named minecraft; it should be added to root's crontab.
Cleaning up old log files:
0 5 * * 0 find /var/www/site/logs -name "*.log" -mtime +14 -delete
Every Sunday, this deletes log files older than 14 days.
Checking that a site is up:
*/5 * * * * curl -fsS https://yourdomain.com > /dev/null || echo "Site is down" >> /var/log/site-check.log
Common cron mistakes
Cron jobs don't run in the same environment as the same command run in a terminal. Most jobs fail silently for these reasons:
- Missing PATH: Cron runs with a very short
PATH; a command that's found in the terminal may not be found in cron. Write the full path of commands (which nodeshows you the path) or add aPATH=line at the top of the crontab. - Relative paths: Cron jobs start in the user's home folder. Always use full paths such as
/home/user/script.shin scripts and file names, or putcd /folder &&before the command. - The
%character: In a crontab,%means a line break. Escape it as\%in uses such asdate +%F. - Execute permission: Make sure the script is executable with
chmod +xand has an interpreter such as#!/bin/bashon its first line. - Lost output: Redirect the job's output and errors to a file (
>> /var/log/job.log 2>&1). Otherwise, when something goes wrong, you can't see why. - Time zone: Cron uses the server's time zone. Check it with
timedatectl; on a server that uses UTC, jobs run at a different hour than your local time. - Overlapping runs: If a long job doesn't finish before its next run time, two copies can run at once. Prevent this by adding
flock -n /tmp/job.lockto the start of the command.
Checking cron logs
To see whether a job ran:
grep CRON /var/log/syslog
If that file doesn't exist on current versions of Ubuntu and Debian, use journalctl -u cron; on AlmaLinux, use journalctl -u crond or the /var/log/cron file. The log shows that the job started; whether it succeeded, you can only tell from the output file you redirected it to yourself.
System-wide cron files
Alongside user crontabs, there are also folders for system-wide jobs:
/etc/cron.d/: Jobs added as separate files by packages and administrators. Lines here also include the name of the user that runs the job after the time fields./etc/cron.daily/,/etc/cron.weekly/,/etc/cron.monthly/: Executable scripts placed in these run once a day, week or month.
For example, Certbot's SSL certificate renewal job and logrotate, which rotates log files, run from these folders or from systemd timers.
Alternative: systemd timers
On current Linux distributions, systemd timers are a strong alternative to cron. The job is written as a service file and the schedule as a timer file. Setting one up takes a little longer than cron, but it has advantages:
- The job's output automatically goes to the
journalctllog. - With the
Persistent=truesetting, jobs missed while the server was off run at boot. - A new run doesn't start before the job's previous run has finished.
You can see all the timers on your server and their next run times with the systemctl list-timers command. For simple jobs, cron is still the fastest solution; for jobs where debugging and reliability matter, you may prefer a timer.
Scheduled jobs on Nodesty
On Nodesty AMD Ryzen 9 9950X VPS plans, you can use cron and systemd timers however you like with full root access; if you're new to Linux commands, start with our Linux commands guide. On our web hosting plans, you can create your scheduled jobs from the cron section of cPanel and DirectAdmin, without SSH access.
Frequently Asked Questions
Why isn't my cron job running?
The most common causes are a command that can't be found because of a missing PATH, relative file paths, a script without execute permission and an unescaped % character in the crontab. Redirecting the job's output to a file and reading the error message usually shows the problem right away.
Which time zone does cron use?
Cron uses the server's system time zone. Many servers run on UTC, so a job you want to run at 03:00 local time has to be scheduled at the matching UTC time. You can see the server's time zone with the timedatectl command and change it if needed.
Can I run a job every 30 seconds with cron?
Cron's smallest unit is one minute. For work you need to run more often, either write the job as a service that waits in a loop or use a systemd timer. If you need something at the level of seconds, a continuously running application is usually the better solution.
Can I set up a cron job on web hosting?
Yes. In cPanel under Cron Jobs and in DirectAdmin under Cronjobs, you can create scheduled tasks without needing SSH access. Using a real cron job instead of WordPress's own scheduler makes scheduled posts and backups run on time, especially on sites with few visitors.
How do I stop a job from running twice at the same time?
If a long-running job doesn't finish before its next run time, a second copy can start. Add flock -n /tmp/job.lock to the start of the command; while the previous run is still going, the new copy won't start at all.
Is there cron on a Windows server?
Windows doesn't have cron; Task Scheduler does the same job. From its graphical interface or with the Register-ScheduledTask command in PowerShell, you can create tasks that run at specific times or when the server starts.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

How to Upgrade Ubuntu Server to the Next LTS Release
How to upgrade an Ubuntu server to the next LTS release: backups, preparation, do-release-upgrade, SSH access, post-upgrade checks and a clean install.

What Is a Load Balancer and How Does It Work?
What is a load balancer and what does it do? Balancing methods, health checks, session handling, load balancing with Nginx, HAProxy and when you need one.

How to Deploy a Laravel App to a VPS
How to deploy Laravel to a server: PHP-FPM, Composer, .env, the database, file permissions, Nginx, queue workers, the scheduler, SSL and shipping updates.