Cron Explained: How Computers Keep a Schedule
Cron is the reason a computer can start a report at 2:30 in the morning while its owner is asleep. It reads a schedule and launches the listed commands, making it a familiar tool for recurring tasks on Linux and other Unix-like systems.
The background program that watches the schedule is called a daemon. A scheduled task is a cron job, and the file listing those jobs is a crontab, short for cron table.
Reading a cron schedule
Here's an example entry in a user's crontab:
30 2 * * * /home/alex/bin/nightly-report
It tells cron to start the program at /home/alex/bin/nightly-report at 2:30 a.m. every day, using the schedule's time zone. That path is an example: the report program must already exist, and the user must have permission to run it.
The five fields before the command describe when it should run:
| Position | What it controls | Value in this example |
|---|---|---|
| First | Minute | 30 |
| Second | Hour, on a 24-hour clock | 2 |
| Third | Day of the month | *, meaning every day |
| Fourth | Month | *, meaning every month |
| Fifth | Day of the week | *, meaning every weekday and weekend |
The asterisk means any allowed value in that field. The Cronie crontab manual describes these fields and the additional syntax for more detailed schedules.
Linux in 100 Seconds
On systems that provide the usual crontab command, crontab -e opens your own schedule for editing, while crontab -l lists it. Neither command automatically shows every scheduled task belonging to other users.
System-wide crontab files can have an extra field naming the account that runs a job. That's why an entry copied from a system file may need changing before it belongs in your personal crontab; the crontab file-format manual explains the distinction.
Starting a task isn't the same as finishing it
Cron can launch a backup program, but that program still has to reach the files, find storage space, and finish writing its copy. A correct schedule doesn't prove that a usable backup exists.
A command can also work in your terminal and fail under cron because it starts with different settings. A shell, the program that interprets commands, and the locations searched for programs may differ from your usual session.
Using full file paths helps avoid some of those surprises. Cronie's cron manual also describes sending job output by email or to system logs, but email delivery depends on a working mail setup.
For an important job, arrange a clear failure alert and keep enough output to investigate what went wrong. A backup deserves an occasional restore test, too: being able to recover a file is the result you're paying attention to.
- Stop breaking your focus to look up a command: the answer is already under your wrist.
- Find what you need fast, with commands grouped by job from files to networking.
- Enough room for a laptop or a keyboard and mouse, on a soft surface that's easy on your wrists.
What happens when the computer is off?
Ordinary cron scheduling assumes the machine is running when a job comes due. If a laptop is shut down at the scheduled time, don't assume cron will replay that missed job when it starts again.
Anacron is a related scheduler designed for daily, weekly, and other periodic jobs on computers that aren't always on. Its manual explains how it tracks elapsed days, rather than requiring a machine to be awake at one exact minute.
Time zones and daylight-saving changes also deserve attention when timing matters. Check the behavior of your system's cron implementation before relying on a particular clock change.
Give the job only the access it needs
A cron job runs with the permissions of its assigned account. Avoid using root, the powerful system administrator account, for a task that works with ordinary user permissions.
Protect the program and its schedule from unauthorized edits. If someone can change a script that a powerful account runs every night, the next scheduled run could carry out that person's instructions.
Before leaving a job unattended, also consider whether one run might still be working when the next starts. Tasks that mustn't overlap need a way to prevent simultaneous runs; the schedule alone doesn't provide that coordination.
What Is a Daemon? The Programs Working Behind Your Apps

System Administration Is the Work That Continues After Setup

Unix: A Family History, a Standard and a Set of Permissions

QUOTE:
"Amateurs hack systems, professionals hack people."
