brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: VISUAL or EDITOR decides which editor crontab -e opens

Cron
~/tips/tip-cron-crontab-e-editor

EDITOR=nano crontab -e

Picks the editor for crontab -e for one command or for good.

crontab -e drops some people into vi and others into nano, and the first time it happens to you in vi, getting out can take a while. I’d rather pick the editor myself.

EDITOR=nano crontab -e

crontab looks at the VISUAL and EDITOR environment variables to pick the editor. Setting one in front of the command, like above, applies to that one run. To make it permanent, put it in your shell config:

echo 'export EDITOR=nano' >> ~/.bashrc

When neither is set, Debian’s crontab falls back to /usr/bin/editor, which is managed by the alternatives system.

What happens after you save is worth knowing too. crontab doesn’t edit the real file in place. It opens a temporary copy and installs it when you close the editor. Until then, your old crontab stays active.

That’s also why editors that return right away cause trouble. A graphical editor like VS Code needs a wait flag, EDITOR='code --wait', or crontab sees an unchanged file and installs nothing. With sudo, remember that root has its own environment, so sudo crontab -e may open a different editor than you expect.

Further reading: crontab(1) manual page, Debian cron, crontab(1) manual page, cronie

Going deeper: Guide: find out why a Linux service failed, with journalctl

More Cron tips echo 'systemctl restart myapp' | at 03:00 tomorrow 55 23 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /usr/local/bin/month-end.sh 30 6 * * mon /usr/local/bin/weekly-report.sh @daily /usr/local/bin/backup.sh sudo ls -l /var/spool/cron/crontabs All Cron tips (32) All topics

Link