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.



3 Answers 3


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

  • 7
    Not at all. "Restore from backup" is the correct answer. +1
    – jscott
    Sep 30, 2010 at 16:42
  • 1
    Is it appropriate to suggest that /var/spool/cron/* ? Jul 5, 2011 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.


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/sorttv.pl


bash ~/scripts/sort_sports.sh


  • Why did this get a -1? Jul 1, 2013 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, 2013 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/ Jul 1, 2013 at 17:44
  • You should have added that it recovers the crontab using the log files in the original answer.
    – mdpc
    Jul 1, 2013 at 17:52
  • 2
    Hi, I just looked and only found the PHP script. Did not find the sh scripts mentioned in your output. One can also simply: grep CRON /var/log/syslog|grep root|cut -d ":" -f 4-9|sort -u --- now a great wok would be to analyze dates and times of commands ran, and regenerate propper crontab with propper timmings based on the timespan of the log
    – cusco
    Nov 23, 2015 at 17:29

You must log in to answer this question.

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