Cron is the clock-based task scheduler of Linux and Unix: a small background program that wakes up once a minute and runs any command whose time has come. A cron job is one of those scheduled commands, written as a single line in a file called a crontab ("cron table"), for example 0 3 * * * /usr/local/bin/backup.sh to run a backup every night at 03:00.
Cron only works while the machine is switched on, so scheduled jobs belong on a server that never sleeps. A Linux VPS runs around the clock, gives you root access to the crontab and lets you pick the server's time zone. Everything below was run on a Debian 13 test server, and the outputs are the ones we got.
Key facts:
- Cron reads three places: each user's crontab (edited with
crontab -e), the system file/etc/crontab, and the files in/etc/cron.d/(cron(8), Debian 13). - A schedule has five fields: minute, hour, day of month, month and day of week. A
*means "every". - Shortcuts exist:
@reboot,@hourly,@daily,@weekly,@monthly,@yearly(crontab(5)). - The smallest step is one minute. Cron does not run jobs it missed while the machine was off.
- Jobs run with a tiny environment: on our Debian 13 server the PATH inside cron was only
/usr/bin:/bin. - A bare
%in a cron line is turned into a newline. Write\%instead. - Output that is not redirected is mailed to the crontab owner, or to the address in
MAILTO.
Cron in 30 seconds
- Open your crontab:
crontab -e(the first time, pick an editor; nano is the easy one).- Add a line: five time fields, then the command with full paths, for example
*/5 * * * * /usr/local/bin/check.sh >> /var/log/check.log 2>&1- Save and close. You should see
crontab: installing new crontab.- Check it:
crontab -l. See it run:journalctl -u cronon Debian and Ubuntu.
What is cron used for?
Anything that should happen on a clock without a person pressing a button: nightly backups, clearing old logs, checking that a website still answers, renewing certificates, pulling a report every weekday morning, or restarting a bot at 04:00. Your Debian server already uses it: /etc/crontab runs the scripts in /etc/cron.daily/, and on our test box those were apt-compat, dpkg and exim4-base.
The name is usually traced to chronos, the Greek word for time. On the Unix history mailing list this is credited to cron's author Ken Thompson through Brian Kernighan, but only second-hand (TUHS archive). The cron in Debian 13 is the package cron 3.0pl1-197; AlmaLinux, Rocky Linux and RHEL ship a different implementation called cronie, with the same crontab format.
How cron works: daemon, crontabs and the cron.daily folders
The cron daemon starts at boot, then "wakes up every minute, examining all stored crontabs", as the Debian manual puts it. It notices edited files by their modification time, so you never restart cron after changing a crontab. There are four places to put jobs:
| Where | Who uses it | Format |
|---|---|---|
Your crontab, edited with crontab -e (stored in /var/spool/cron/crontabs/<user>) | Each user, jobs run as that user | 5 time fields + command |
/etc/crontab | The system | 5 time fields + user name + command |
/etc/cron.d/<file> | Packages and admins (certbot drops one here) | Same as /etc/crontab; file name without dots |
/etc/cron.hourly, .daily, .weekly, .monthly | Scripts that just need "once a day" | Executable scripts, no schedule line, no dots in the name |
On Debian 13 the stock /etc/crontab runs the hourly folder at minute 17, the daily one at 06:25, the weekly one on Sunday at 06:47 and the monthly one on the 1st at 06:52 (when anacron is not installed). Files in /etc/cron.d/ and the folders are skipped if their name contains a dot, so backup.sh in /etc/cron.daily/ never runs; call it backup. Check what would run with run-parts --test /etc/cron.daily.
The five time fields
Every crontab line is five fields and a command. Read it left to right: minute, hour, day of the month, month, day of the week.
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12 or jan, feb ...)
| | | | .---- day of week (0 - 7, Sunday = 0 or 7, or sun, mon ...)
| | | | |
30 2 * * 1-5 /usr/local/bin/report.sh
= at 02:30, every month, Monday to Friday
Inside a field, * means every value, 1-5 is a range, 1,15 is a list and */10 means every tenth. One surprise: if you restrict both day of month and day of week, cron runs when either matches, so 30 4 1,15 * 5 runs on the 1st, the 15th and every Friday (crontab(5)). Cron also checks your line when you save it; 61 * * * * was refused with bad minute and errors in crontab file, can't install.
Cron examples: common schedules
| Schedule | Runs |
|---|---|
* * * * * | Every minute |
*/5 * * * * | Every 5 minutes (00, 05, 10 ...) |
*/15 9-17 * * * | Every 15 minutes from 09:00 to 17:45 |
0 * * * * or @hourly | Every hour, on the hour |
0 */6 * * * | Every 6 hours: 00:00, 06:00, 12:00, 18:00 |
0 3 * * * | Every day at 03:00 |
0 9,17 * * * | Twice a day, 09:00 and 17:00 |
@daily (same as 0 0 * * *) | Every day at midnight |
30 8 * * 1-5 | Weekdays at 08:30 |
@weekly (same as 0 0 * * 0) | Sunday at midnight |
0 2 1 * * | The 1st of every month at 02:00 |
@monthly | The 1st of every month at midnight |
@yearly | 1 January at midnight |
@reboot | Once, each time cron starts after a boot |
How to create a cron job, step by step
1. Make sure cron is there. In our minimal Debian 13 image it was not installed, so check first:
systemctl is-active cron
sudo apt install cron # only if the line above says inactive or the unit is missing
2. Open your crontab. The first time, you pick an editor:
crontab -e
no crontab for demo - using an empty one
Select an editor. To change later, run select-editor again.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
Choose 1-2 [1]:
3. Go to the bottom of the file (the top is comments) and add one job per line. Our first test job writes the time to a file every minute:
* * * * * echo "$(date +\%T) cron says hello" >> $HOME/cron-test.log
4. Save and quit (in nano: Ctrl+O, Enter, Ctrl+X). Cron confirms with crontab: installing new crontab.
5. List your jobs with crontab -l, and after a few minutes look at the file:
cat ~/cron-test.log
23:32:01 cron says hello
23:33:01 cron says hello
23:34:01 cron says hello
Note the :01: cron starts jobs in the first second or so of the minute.
6. Be careful with crontab -r. It deletes your whole crontab at once with no question, and r sits next to e on the keyboard. Our test: crontab -r, then crontab -l answered no crontab for demo. Keep a copy and use the asking version:
crontab -l > ~/crontab-backup.txt # save
crontab -ri # asks: really delete demo's crontab? (y/n)
crontab ~/crontab-backup.txt # restore from the copy
Root jobs go in root's crontab with sudo crontab -e. Running a job as root when it does not need it is a security risk; give it its own user if you can.
Where cron output and logs go
Two different things get recorded: that a job started, and what the job printed.
The start is logged by cron itself. Debian 13 and Ubuntu use the systemd journal (Debian 13 had no /var/log/syslog at all on our server):
journalctl -u cron --no-pager -o cat | tail
pam_unix(cron:session): session opened for user demo(uid=1000) by demo(uid=0)
(demo) CMD (date +%H:%M >> $HOME/percent-good.log)
(demo) CMD (echo "$(date +%T) cron says hello" >> $HOME/cron-test.log)
(demo) CMD (env > $HOME/cron-env.txt)
pam_unix(cron:session): session closed for user demo
Leave out -o cat to see the date and time at the start of each line. On AlmaLinux, Rocky Linux and RHEL the daemon is called crond, so use journalctl -u crond; the classic text log there is /var/log/cron, written by rsyslog. Which file gets cron messages is set in the rsyslog config, so check with grep -r cron /etc/rsyslog.conf /etc/rsyslog.d/.
What the job prints is mailed to you if you do not redirect it. Our server had a local mail program, so failed jobs landed in /var/mail/ with a subject like Cron <demo@lab-cron> date +. Without a mail program that output is lost. Three choices:
- Redirect to a log file:
>> /var/log/myjob.log 2>&1. This is the safe default. - Set
MAILTO=you@example.comat the top of the crontab to get mail from every job that prints anything (needs a working mail setup). - Set
MAILTO=""to send no mail at all.
Classic cron mistakes (and how we reproduced them)
1. Command not found: PATH is short in cron
We made cron dump its environment with * * * * * env > $HOME/cron-env.txt:
HOME=/home/demo
LOGNAME=demo
PATH=/usr/bin:/bin
LANG=en_US.UTF-8
SHELL=/bin/sh
PWD=/home/demo
No /usr/local/bin, no /usr/sbin, none of your .bashrc. A script in /usr/local/bin called by name failed; the same script with its full path worked:
* * * * * hello.sh >> $HOME/path-bad.log 2>&1
* * * * * /usr/local/bin/hello.sh >> $HOME/path-good.log 2>&1
==> path-bad.log
/bin/sh: 1: hello.sh: not found
==> path-good.log
23:35:01 hello from a script
Fix: use full paths (command -v mysqldump shows them), or put a PATH=... line at the top of the crontab. Also note the shell is /bin/sh, not bash, so bash-only syntax fails unless the script has its own #!/bin/bash line.
2. The percent sign
This line looks fine in a terminal but breaks in cron:
* * * * * date +%H:%M >> $HOME/percent-bad.log
Cron cut the line at the first % and fed the rest to the command as input. The journal shows what really ran, (demo) CMD (date +), the redirect vanished, percent-bad.log was never created, and a mail arrived every minute instead. The escaped version works:
* * * * * date +\%H:\%M >> $HOME/percent-good.log
23:32
23:33
23:34
Simplest rule: if a command needs %, put it in a script and call the script.
3. The wrong time zone
Cron uses the server's time zone, and many cloud images ship with UTC. A "03:00" job then runs at 04:00 in Prishtina in winter. Debian's cron has no per-user time zone; a TZ= line only changes what the commands see, not when they run (crontab(5)). Set the server's zone and restart cron:
sudo timedatectl set-timezone Europe/Belgrade
sudo systemctl restart cron
timedatectl | grep "Time zone"
Time zone: Europe/Belgrade (CET, +0100)
Daylight saving time has its own rules: jobs whose time is skipped when clocks jump forward run soon after the change, and jobs are not run twice when clocks go back (cron(8)). Avoid scheduling important jobs between 02:00 and 03:00 local time.
4. Overlapping runs: use flock
If a job runs every minute but sometimes takes 90 seconds, two copies run at once, and two backups writing the same file is how you lose data. flock holds a lock file; with -n a second copy gives up at once instead of waiting:
* * * * * flock -n /tmp/slow.lock -c 'echo "$(date +\%T) start"; sleep 90; echo "$(date +\%T) end"' >> $HOME/slow.log 2>&1 || echo "$(date +\%T) skipped, previous run still busy" >> $HOME/slow.log
23:32:01 start
23:33:01 skipped, previous run still busy
23:33:31 end
23:34:01 start
5. Permissions and file names
A job runs as the crontab's owner, so a user job cannot write to /var/backups or restart services. Scripts must be executable (chmod 755). Files in /etc/cron.d/ must belong to root and not be writable by group or others, and dots in names make cron skip them silently.
Cron vs systemd timers
systemd timers are the other scheduler on modern Linux. Debian itself uses them for apt-daily.timer, apt-daily-upgrade.timer and certbot.timer on our test server. Neither is "better"; they suit different jobs.
| cron | systemd timer | |
|---|---|---|
| Setup | One line | Two files: a .service and a .timer |
| Missed runs while powered off | Skipped | Run at next boot with Persistent=true |
| Logs | Start line in the journal, output by mail or your redirect | Full output per unit in the journal |
| Spread the load | By hand (pick odd minutes) | RandomizedDelaySec= |
| Precision | To the minute | Within AccuracySec=, 1 minute by default |
| Best for | Quick jobs, user jobs, anything portable | System services that need ordering, limits and logs |
Details are in the systemd.timer manual. On a VPS that is always on, the missed-run difference rarely matters, which is why cron is still the quickest way to start.
Real cron use cases, one line each
We installed each of these lines in the test crontab to check the syntax, and ran the ones that need no database, domain or remote host (tar, find, curl, rsync). Run them from root's crontab, or a user that owns the files, and swap in your own paths.
| Job | Crontab line |
|---|---|
| Database backup every night | 30 2 * * * mysqldump --single-transaction --all-databases | gzip > /var/backups/db-$(date +\%F).sql.gz |
| Website files backup | 0 3 * * * tar -czf /var/backups/www-$(date +\%F).tar.gz -C /var/www site |
| Copy backups off the server | 0 4 * * * rsync -a /var/backups/ backup@backup.example.com:/srv/web1/ |
| Delete logs older than 14 days | 15 1 * * * find /var/log/myapp -name "*.log" -mtime +14 -delete |
| Website up? (mails you when not) | */5 * * * * curl -fsS -m 10 -o /dev/null https://example.com/ || echo "example.com check failed" |
| Weekly database maintenance | 0 5 * * 0 mysqlcheck --all-databases --optimize --silent |
| WordPress cron from the system | */5 * * * * curl -s -o /dev/null https://example.com/wp-cron.php |
| Scraper or report on weekdays | 0 7 * * 1-5 /usr/bin/python3 /opt/report/daily.py >> /var/log/report.log 2>&1 |
| Clear cache files older than 6 hours | 0 */6 * * * find /var/cache/myapp -type f -mmin +360 -delete |
| Mirror a folder | */30 * * * * rsync -a --delete /var/www/ /srv/mirror/ |
| Daily disk report by mail | MAILTO=you@example.com then 0 8 * * * df -h / |
| Nightly bot restart | 0 4 * * * /usr/bin/systemctl restart tradingbot |
A few notes from testing. The uptime check against a name that does not exist sent a mail reading curl: (6) Could not resolve host: down.invalid and down.invalid check failed, while the working site sent nothing, which is what you want. For WordPress, first add define( 'DISABLE_WP_CRON', true ); to wp-config.php; otherwise WordPress checks its schedule on every page load (WordPress developer docs). A restart is only a crutch for a bot that leaks memory; the guide to hosting a Telegram or Discord bot on a VPS runs bots under systemd so they restart on their own after a crash.
Two jobs you should not build yourself on Debian. Certificates: the certbot package installs certbot.timer plus an /etc/cron.d/certbot file that only runs on systems without systemd. Updates: unattended-upgrades runs from the apt timers above; our automatic security updates guide shows how to make it run every hour. For backups, a local tar file is a start, not a backup plan: copy it elsewhere with restic to off-site storage, and read the VPS backup and restore guide for what our free weekly server backups already cover. To be told when a job's target goes down rather than reading mail, pair cron with Uptime Kuma monitoring.
Cron on Windows?
Windows has no cron. Its equivalent is Task Scheduler, which Microsoft describes as running tasks when chosen "triggers" are met: a time, a daily or weekly schedule, system start or user logon (Microsoft Learn). You can use the Task Scheduler window or the schtasks /create command. On a Windows server the same logic applies as on Linux: the machine must be on for the task to run.
Online cron services vs cron on your own VPS
If you have no server, web cron services will call a URL on a schedule. They are fine for pinging a page, but they only make HTTP requests and come with limits. Checked in November 2026:
| cron-job.org | GitHub Actions schedule | Cron on your own VPS | |
|---|---|---|---|
| What it runs | Calls a URL | A workflow in a repository | Any command or script |
| Shortest interval | 1 minute | 5 minutes, "can be delayed" at busy times | 1 minute |
| Time limit per run | 30 seconds | 6 hours per job on GitHub-hosted runners | None, it runs until done |
| Catch | Reads up to 64 KB of output | UTC by default; disabled after 60 days without activity in public repos | You maintain the server and set its time zone |
Sources: cron-job.org FAQ, GitHub Docs, schedule event and GitHub Actions limits. A database dump, a scraper that runs for ten minutes or an rsync to another server cannot be done through a URL ping. On a VPS the jobs run next to your data, around the clock, with no timeout, and you choose the time zone. RS Computers runs KVM VPS and VDS servers in Amsterdam, Dublin and Prishtina with full root access, so your crontab is yours from the first login; if the server is new, do the Debian 13 security checklist before you add jobs.
Frequently asked questions
What is a cron job in simple words?
A cron job is a command that a Linux or Unix computer runs by itself on a schedule, such as every five minutes or every night at 03:00. The schedule and the command sit on one line in a crontab file, and the cron program checks those lines once a minute.
What does crontab mean?
Crontab is short for "cron table". It is both the file that holds your scheduled jobs and the command that edits it: crontab -e to edit, crontab -l to list and crontab -r to delete it.
What does * * * * * mean in cron?
Five stars mean every minute of every hour of every day. The fields are minute, hour, day of month, month and day of week, and a star in a field means "any value". Replace stars with numbers to narrow it down: 0 3 * * * is 03:00 every day.
Why does my cron job work in the terminal but not in cron?
Usually because cron's environment is much smaller than your login shell. On Debian 13 cron's PATH is only /usr/bin:/bin and the shell is /bin/sh. Use full paths, escape every % as \%, and redirect output to a log file with 2>&1 so you can read the error.
How do I see if a cron job ran?
On Debian and Ubuntu run journalctl -u cron; each run shows a line with CMD and the command. On AlmaLinux, Rocky Linux and RHEL use journalctl -u crond or /var/log/cron. The log only shows that the job started; to see what it did, redirect its output to a file.
Can cron run every 30 seconds?
Not directly; one minute is the smallest step. The usual workaround is two identical lines, the second one waiting 30 seconds before it starts the command. For anything that frequent, a small service with its own loop or a systemd timer is cleaner.
Does cron run when the computer is off or asleep?
No. Jobs whose time passes while the machine is off are skipped. That is why scheduled work belongs on a server that stays on, such as a VPS, or under a systemd timer with Persistent=true, which catches up after boot.
Need a hand?
Cron is only as reliable as the machine it runs on. If your jobs live on a laptop or a free tier that sleeps, move them to a VPS or VDS with NVMe in Amsterdam, Dublin or Prishtina: it is on 24/7, you set its time zone, and free weekly backups come with every server. Heavy scheduled work, such as large database dumps, scrapers or trading bots that must not wait for CPU, fits a VDS with dedicated vCPUs. If you would rather have the backup jobs, monitoring and scripts set up for you, we do custom offers, custom setups and systems built for you, quoted per job: write to us on Telegram or by email at info@rscomputers-ks.com.