How I deleted my crontab :( and learned that e and r are two adjecent keys!

Scroll this

For more then 10 years I used to edit my crontabs relaying on my muscle memory. Typing and pressing enter without checking the cmd line like this:

But one day my muscle memory failed me and I typed this:

At first I thought no biggy, just a tipfeler, but alas, -r actually removed crontab! 🙁

So programmers of the crontab in their infinite wisdom assigned option to edit and remove crontab to two adjacent keys. And of course when removing a crontab they thought that no conformation is necessary. In case you want to remove the crontab and also want to have a chat with crontab about it, you need to type this:

And this makes perfect sense:

Because of course, if you type  crontab -r according to the crontab programmers there is no way that, maybe just maybe, it is a typo  – so no conformation is needed.

But if you type crontab -ir then maybe you are not sure that you want to remove the crontab (why in earth you would type -i if you are sure??) – so conformation is absolutely essential.

The moral of the story is:

  • read the cmd line before pressing return, it doesn’t matter how confidant and experienced you are
  • make your backups
  • crontab guys, really? -r without conformation, -ir with conformation?

No backup, what can I do?

In case you don’t have backup – there is cron log! In CentOS you can find it at: /var/log/cron. On Ubuntu cron  log is probably in /var/log/syslog.
This is not crontab file backup, but execution log from which you can reverse engineer your lost crontab file.

References

  • man crontab
  • man cron
  • man 5 crontab

Submit a comment