Server Fault is a question and answer site for system and network administrators. 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 was trying to create a cron on the production environment and so I created crontab.txt file with my new cron command and ran crontab crontab.txt file but instead of appending to existing cron job list, it accidently deleted all crons and now I only have my cron on prod.

How can I retreive earlier crons that were set and append my new cron to it.


share|improve this question

migrated from Sep 30 '10 at 16:41

This question came from our site for professional and enthusiast programmers.

up vote 15 down vote accepted

Would it add insult to injury to suggest restoring your crontab from backups?

share|improve this answer
Not at all. "Restore from backup" is the correct answer. +1 – jscott Sep 30 '10 at 16:42
Is it appropriate to suggest that /var/spool/cron/* ? – Craig Hyatt Jul 5 '11 at 18:11

First of all: Always make backups!


You can try to have a look at /var/log/cron and build your crontab again.

  1. Have a look at the logfile
  2. Take the first command and do grep commandname1 /var/log/cron
  3. Figure out the systematic behind the times the command was run
  4. put that entry to your new crontab
  5. execute cat /var/log/cron | grep -v commandname1
  6. Take the next command and grep for it
  7. Figure out the systematic behind the times the second command was run
  8. put that entry to your new crontab
  9. execute cat /var/log/cron | grep -v commandname1 | grep -v commandname2
  10. Repeat until you covered all commands

Now you should also execute the grep on older cronlogs to find out jobs that might be run only once in a month.

share|improve this answer

I made a PHP script that does a full recovery of your crontab, based on the log.

It outputs a single instance of every cron command run by the user for the last week.

I put it here

Here is a sample output:

perl ~/sorttv/


bash ~/scripts/


share|improve this answer
Why did this get a -1? – Dan Green-Leipciger Jul 1 '13 at 14:48
I'll be is that is because it does not answer the immediate problem, not what to do in the future. However, this is only a guess on my part. – mdpc Jul 1 '13 at 16:34
I had this problem myself today, and the best answer I could find was sort through 800 lines of log file. So I made a PHP script that sorted through the log and isolated all of cron commands. After I solved my own problem, I uploaded the file to github and added a readme so that others could benefit from it. Then I got a -1/ – Dan Green-Leipciger Jul 1 '13 at 17:44
You should have added that it recovers the crontab using the log files in the original answer. – mdpc Jul 1 '13 at 17:52
Great script. Saved me. Thank you so much. – MeV Jul 22 '15 at 14:28

protected by MadHatter Jul 1 '13 at 13:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.