All posts

Setting Up a Cron Job: The Complete Beginner's Guide

September 9, 2026

Setting up a cron job takes about five minutes if nothing goes wrong — and it's the "if" that trips up almost everyone the first time. Most tutorials walk you through crontab -e, hand you a syntax table, and stop. What they leave out is whether the job has permission to run, whether it can find the commands it depends on, and whether you'll know if it silently stopped working. This guide covers the full lifecycle — write, verify, monitor — so the job you set up today is still running correctly next month.

What You Need Before You Start

Before touching a crontab file, confirm three things. First, check that cron is installed and the daemon is running — on most Linux distributions this is crond (Vixie-cron or Cronie), checked with systemctl status cron or systemctl status crond. If it's not running, no schedule you write will fire. Second, know the absolute path to the script or command you want to run — ./backup.sh works in your terminal but fails under cron, which doesn't run from your shell's working directory. Third, make sure the script has execute permission (chmod +x yourscript.sh). These three checks resolve most "my cron job did nothing" complaints before they happen.

Step 1: Open Your Crontab

The command to edit your personal schedule is crontab -e. The first time you run it, most systems prompt you to choose a default editor — nano is friendlier if you're unsure, though vim works identically once you're comfortable. This opens your per-user crontab, separate from the system-wide /etc/crontab file and the /etc/cron.d/ directory. Per-user crontabs don't require a username field per line and are what almost every beginner should use; /etc/crontab is reserved for system-level jobs and includes an extra user column. On shared or restricted systems, access is sometimes gated by a cron.allow file — if crontab -e throws a permission error, check there first.

Step 2: Write the Schedule and Command

Every cron line follows the same five-field schedule format, followed by the command to run:

# minute  hour  day-of-month  month  day-of-week  command
    *      *         *          *         *        /path/to/script.sh

A job that runs daily at 2:30 AM looks like this:

30 2 * * * /home/user/scripts/backup.sh

And one that runs every Monday at 9 AM:

0 9 * * 1 /home/user/scripts/weekly-report.sh

For the full breakdown of special characters, step values, ranges, and less obvious flag behavior, see Cron Job Command: Syntax, Crontab Flags & Silent Failures. Once comfortable with the basic format, 15 Cron Job Examples You Can Copy and Paste Today is a fast way to grab a working line for common tasks instead of writing one from scratch.

Step 3: Save and Verify It's Registered

Save and exit using the editor's normal command (:wq in vim, Ctrl+O then Ctrl+X in nano). Cron doesn't confirm anything visually — the only way to know your edit stuck is to run crontab -l, which lists every job registered under your user. If your new line isn't there, the save didn't take, or you edited the wrong file. This check — write, then immediately confirm with crontab -l — is the step most beginners skip, and it's the fastest way to verify cron job setup before you walk away. For more ways to inspect scheduled jobs, including system-wide entries, there's a dedicated guide on viewing cron jobs across different setups.

Step 4: Avoid the Setup Mistakes That Cause Silent Failures

A handful of mistakes account for nearly every "it worked when I ran it manually but not under cron" report. Missing execute permissions on the script file is the most common — cron will simply fail to run it, without a visible error. Relative paths and missing environment variables are next: cron runs with a minimal environment and often no PATH at all, so a script calling python or node without a full path may run fine in your terminal and do nothing under cron. Always use absolute paths for both the script and any binaries it calls. Third, unredirected output: cron mails command output to the system mail spool by default, and on a server with no mail configured, that output just accumulates or vanishes — redirect it explicitly with >> /path/to/log.txt 2>&1 so you have a record. Finally, remember that day-of-month and day-of-week are combined with OR logic, not AND — a schedule like 0 0 1 * 5 runs both on the 1st of the month and every Friday, which surprises people expecting "the first Friday."

Step 5: Confirm the Job Actually Ran

Permissions fixed and syntax correct doesn't guarantee execution — you still need evidence. Check your system's cron log, typically /var/log/syslog (Debian/Ubuntu) or via journalctl -u cron, and grep for your job's command or cron ID to see the invocation timestamp. If you redirected output as described above, your own log file is the fastest confirmation. This tells you the job ran once. It tells you nothing about tomorrow, next month, or after the next server reboot — and that gap is exactly where cron jobs quietly stop working without anyone noticing for weeks.

Setup Is Done — Now What Happens When It Fails?

Cron has no built-in alerting. It won't tell you if a script exits with an error, hangs indefinitely, or never runs because the server rebooted without the daemon restarting. Compare this to systemd timers, which offer somewhat better integration with system logging but still stop short of proactive alerts. The standard fix across the DevOps world is a monitored HTTP ping: your job calls a unique URL when it starts and finishes, and if that ping doesn't arrive on schedule, you get notified instead of finding out from a customer or a downstream failure three weeks later. This is precisely the layer Cronevra adds — it watches for the expected ping, tracks execution history, and sends an alert the moment a run goes missing or fails, closing the exact blind spot manual crontab setups leave open. If you're ready to see what fits your setup, the pricing page lays out the plans.

If editing crontab directly isn't your preference, the Cron Job Editor: Terminal, GUI, and Online Tools Compared guide walks through alternatives.

You've now got a cron job scheduled and confirmed — but it's running silently in the background with zero notification if it fails, stalls, or the server reboots without it. Wrapping that job in a monitored ping through Cronevra is the missing last step, turning silent failures into an alert you actually see.

Frequently Asked Questions

How do I set up a cron job on Linux for the first time?

Run crontab -e to open your personal crontab, add a line in the five-field schedule format followed by the absolute path to your script, then save and confirm it with crontab -l. Before that, verify the cron daemon is running and your script has execute permission — these two checks prevent most first-time failures.

What command do I use to add a new cron job?

Use crontab -e to open your user crontab in a text editor, then add a new line with the schedule and command. This edits your per-user crontab, separate from the system-wide /etc/crontab file.

Why does my newly created cron job not run at all?

The most common causes are missing execute permissions on the script, using a relative path instead of an absolute one, or relying on a command that isn't in cron's limited PATH. crontab -l also confirms the line actually saved — a failed save looks identical to a job that silently didn't run.

Do I need root access to set up a cron job?

No — any user with crontab access can create jobs with crontab -e under their own account, without root privileges. Root access is only needed for system-wide jobs placed in /etc/crontab or /etc/cron.d/, or if a cron.allow file restricts crontab use on that system.

How can I tell if my cron job actually executed successfully?

Check the system cron log (/var/log/syslog or journalctl -u cron) for an entry matching your job's timestamp, or review your own redirected output log if you set one up. Neither method tells you about future runs, though — that requires ongoing monitoring rather than a one-time check.

Can I set up a cron job without using the terminal?

Yes — several GUI and online tools let you build and manage cron schedules without touching crontab -e directly. The Cron Job Editor comparison covers the terminal, GUI, and online options side by side.