crontab -r instead of
crontab -e and all my
cron jobs have been removed.
What is the best way (or is there one) to recover those jobs?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
crontab -r removes the only file containing the cron jobs.
So if you did not make a backup, your only recovery options are:
/var/log/cron. The file will help you rewrite the jobs again.
grep CRON /var/log/syslog
It sucks, but if you run
crontab -r your crontab is gone forever. And unless you have a backup of it somewhere, you must grep through syslog files to get an idea of what/when jobs were being run, and recreate.
A good trick to avoid such problem is to add the following line to your crontab:
@daily crontab -l > $HOME/.crontab
This way your crontab is backed up every day to
$HOME/.crontab, so if you delete it by accident, a relatively recent copy is available and can be installed by:
crontab < $HOME/.crontab