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: crontab -r deletes every cron job without asking, so run crontab -l first

Cron
~/tips/tip-cron-crontab-r-needs-backup

crontab -l > ~/crontab.backup

Saves your crontab to a file and makes crontab ask before it removes everything.

The r key sits right next to e, and a typo in `crontab -e` wipes the whole crontab with no prompt.

crontab -l > ~/crontab.backup
crontab -ri
crontab ~/crontab.backup   # restore

crontab -l prints the current table, so the first line is a one-second backup. -i changes -r into a version that asks for y or Y before it deletes, which is a good habit to alias. Installing a file with crontab file replaces the table in one go, which is also how you restore. The -i option exists in the Debian and Ubuntu cron, but not every cron implementation has it. Keep the real crontab in a git repository and install it from there if you want a history.

Further reading: crontab(1) manual page

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 EDITOR=nano crontab -e 30 6 * * mon /usr/local/bin/weekly-report.sh @daily /usr/local/bin/backup.sh All Cron tips (32) All topics

Link