How to set up a cron job — so your script runs itself, on schedule

You've got a script: it makes a backup, sends a report, cleans a folder. There's just one problem — you have to run it by hand. Every day. At the same time. Boring, and easy to forget.
cron is the system's built-in alarm clock. You describe "what to run and when" once, and after that it fires on its own while you're busy with something else. Let's go step by step through setting up such a job without tripping over the usual rakes.
Step 1. Open the schedule
On Linux and macOS every user has their own list of cron jobs — a crontab. You open it with:
crontab -e
The first time, the system asks which editor to edit with (easiest is nano — it labels the hotkeys at the bottom). A file opens where each job is written on one line.
Step 2. Read the five-field syntax
A job line looks like this: five time fields, then a command. The five fields, left to right, are:
minute hour day-of-month month day-of-week
An asterisk * means "any value." Sample schedules:
0 9 * * *— every day at 9:00 a.m.*/15 * * * *— every 15 minutes.0 3 * * 1— at 3:00 a.m. on Mondays (day of week: 0 or 7 — Sunday, 1 — Monday).30 23 1 * *— at 11:30 p.m. on the 1st of every month.
Read it "leftmost is often, rightmost is rare": the far-left field is minutes, the far-right is days of the week. If you get tangled — open a crontab generator, type "every day at 9," and peek at the line.
Step 3. Write the job with full paths and a log
Here's a working line in full:
0 9 * * * /usr/bin/python3 /home/me/backup.py >> /home/me/cron.log 2>&1
Let's break down the tail — it matters:
- Full paths to everything. Not
python3, but/usr/bin/python3. Notbackup.py, but the full path to the file. cron runs in a "bare" environment and knows almost nothing about your usual paths — more on that below. >> /home/me/cron.log— append all the script's output to a log file.2>&1— send errors there too (not just normal output). Without this tail errors just vanish, and you won't understand why the job is "silent."
Save the file and exit (in nano — Ctrl+O, Enter, then Ctrl+X). cron picks up the change on its own.
Step 4. Check that the job was saved
Look at the current list of jobs:
crontab -l
Your line should be there. And separately — run the script by hand first, with the exact command that sits after the time fields:
/usr/bin/python3 /home/me/backup.py
If it fails by hand, cron isn't to blame — fix the script itself. It only makes sense to test the schedule on a script that already works.
What you'll get
From then on the system calls your command at the appointed time — at 3 a.m., or every 10 minutes. You forget about it, and it does its job. Peek into cron.log and you can see whether it ran and what it printed.
Want to remove a single job — crontab -e again and delete its line. But beware the crontab -r command: with no questions asked it wipes the entire list of jobs at once, not just the last one. It's easy to hit it instead of -e and lose all your schedules.
Two rakes everyone steps on:
- cron doesn't see your environment. It runs without your
PATHand without an activated Python virtual environment. Hence "works by hand, not from cron." The cure — absolute paths to everything and running python straight from the venv (/home/me/venv/bin/python). If the job is silent — start right here. - The computer has to be on. cron on a laptop won't fire while the laptop sleeps or is off. For jobs that must run around the clock, cron goes on a server that's always online.
FAQ
How do I test a cron job without waiting for the right time?
Don't wait for 9 a.m. — temporarily set the schedule to * * * * * (every minute) and watch the log for a new entry. Once you've confirmed it runs, put the normal schedule back. That way testing takes a minute, not a day.
What does */5 mean in a cron field?
The slash is a step. */5 in the minutes field means "every 5 minutes": 0, 5, 10, 15, and so on. Likewise */2 in the hours field — every two hours. Handy when you need "regularly" rather than "at a specific moment."
Does cron exist on Windows?
There's no classic cron on Windows — it has its own thing, the Task Scheduler, with the same "run this on schedule" idea, but through windows rather than a crontab line. On a server (almost always Linux) and on macOS, though, cron works exactly as described above.
Short story-lessons, an agent simulator and daily practice — in our mobile app. Free.





