Recover cron jobs accidently removed with crontab -r

crontab -r removes the only file containing the cron jobs.

So if you did not make a backup, your only recovery options are:

  • On RedHat/CentOS, if your jobs have been triggered before, you can find the cron log in /var/log/cron. The file will help you rewrite the jobs again.
  • Another option is to recover the file using a file recovery tool. This is less likely to be successful though, since the system partition is usually a busy one and corresponding sectors probably have already been overwritten.
  • On Ubuntu/Debian, if your task has run before, try grep CRON /var/log/syslog

If you have no /var/log/cron file you can recover the commands (but not the timings) from the syslog.

grep 'CRON.*(yourusername)' /var/log/syslog

you can then figure out most timings by looking at the datestamps.

Tags:

Linux

Cron