The proper way to edit your crontab

December 22nd, 2005 | Tags:

Time to break my habit of using crontab -e. As we all know this opens our default EDITOR and allows us to quickly edit and save our cron jobs. This is a huge risk. If, for example, you find yourself logged in on a strange system and EDITOR is set to something you don’t know, you’re much more at risk to accidentally erase your crontab.

The proper way to edit your crontab is as follows:

crontab -l > /tmp/mycrontab
vi /tmp/mycrontab
(make your changes)
crontab /tmp/mycrontab

Feel free to put the mycrontab file in your home directory (I just used /tmp as an example).

By following the above process you are creating a backup of your crontab and you have full control of the editor you will use to make your changes. You’ll thank me the next time you mistype and enter crontab -r (-r: Remove the current crontab) instead of the crontab -e you thought you typed.

Comments are closed.