Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have accidentally wiped out all my cron jobs. I'm not sure what I have done. I don't remember deleting entries from it by issuing crontab -e. What are the possible ways that the cron jobs can be completely wiped out?

share|improve this question
up vote 7 down vote accepted

If you type crontab with no arguments, it reads a crontab from standard input. If you then type Control-D, it will create an empty crontab, overwriting your previous crontab. (Control-C aborts the command and leaves your crontab alone.)

I avoid this by never using crontab -e (edit crontab) or crontab with no arguments (which reads from stdin). Instead, I keep my crontab entries in a separate file, which I maintain in a source control system, and run the crontab command with that file name as an argument.

(I temporarily clobbered my own crontab while writing this answer, knowing that I could recover it.)

share|improve this answer
thanks. Are there any ways to recover it? – Jason Yeo Mar 15 '12 at 2:07
If you didn't already save a copy of it, none that I know of. The system probably keeps your crontab in /var/spool/cron/crontabs/foo, where foo is your user name; if you have some way of recovering a previous version of that file, you might have a chance. In other words, it comes down to whether you can recover old deleted files in general. Do you have backups? – Keith Thompson Mar 15 '12 at 4:11
@JasonYeo you might be able to recover it using PhotoRec (based on TestDisk), but if that section of the disk was overwritten, it's possible you may not be able to recover the file (the filesystem you use will also affect this). – Breakthrough Jul 31 '13 at 17:44

If you type crontab -r instead of crontab -e by mistake (e and r are next to each other), your crontab will be removed as well.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .