crontab -e Explained: Edit Your Scheduled Jobs Without Breaking Them
crontab -e opens your personal list of scheduled jobs in a text editor. You change the lines, save the file, and cron reads the new version within a minute. No restart, no reload command.
That is the whole idea. The problems start when the editor does something you did not expect, or when a line looks right but never runs. Here is what to check.
What opens, and how to save
The command uses the editor named in $EDITOR. On many servers that is vi, which is not friendly to a first-time user. If you see a screen full of tildes and do not know what to type:
- Press
Esc. - Type
:q!and pressEnterto leave without saving. - Run
export EDITOR=nano, thencrontab -eagain. Nano shows the available keys at the bottom of the screen.
In nano: Ctrl+O, then Enter saves. Ctrl+X closes the editor. In vim: Esc, then :wq, then Enter.
What a crontab looks like
Every job is one line: five time fields, then the command.
0 3 * * * /usr/local/bin/backup.sh
This runs the script at 03:00 every day. Lines that start with # are comments. Blank lines are fine.
The traps that silently discard work
The file must end with a newline. Some cron implementations drop an unterminated last line without any message. If your new job is the last line and never runs, press Enter at the end of the file and save again.
A % sign in the command becomes a newline. Cron treats % as a line break in the command part. If you really need one — a date format inside a date call, for example — escape it as \%.
The environment is not your shell. Cron runs commands with a minimal PATH, usually /usr/bin:/bin, and without your profile. python3 script.py may work in a terminal and fail in cron. Use absolute paths: /usr/bin/python3 /home/me/script.py.
Errors go nowhere unless you send them somewhere. Add a redirect when you want a trace:
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
One typo hides the whole schedule. crontab -e validates the file when you save. If it refuses the edit, nothing is written and the old schedule keeps running — read the message instead of saving again.
Check before you walk away
crontab -lprints the file cron actually holds. If your job is missing here, it was never saved.- Paste the line into the parser and read it back in plain English, field by field — the reading method is the same one. It catches a forgotten field and a schedule that does not mean what it looks like.
- If the job still does not fire, work through the five checks for a job that never runs (or the short mistakes checklist): timezone, permissions, and the log trail are the usual suspects.