yo8192 / fcron

fcron is an advanced cron for Linux/Unix systems
http://fcron.free.fr
GNU General Public License v2.0
134 stars 13 forks source link

-r is DANGEROUS option #24

Open PSLLSP opened 7 months ago

PSLLSP commented 7 months ago
# fcrontab -V
fcrontab 3.2.1 - user interface to daemon fcron
Copyright 2000-2016 Thibault Godouet <fcron@free.fr>
This program is free software distributed WITHOUT ANY WARRANTY.
See the GNU General Public License for more details.

fcrontab -r is dangerous command, it can fatally damage server. A warning and confirmation should be printed before crontab is removed. I damaged my test machine, just a small typo and crontab of root user was removed, no undo.. :-(


How to restore crontab from a text file?

1) backup crontab: fcrontab -l > backup.crontab 2) delete crontab: fcrontab -r 3) how to restore backup from file backup.crontab ?

One option is to run fcrontab -e, that will start an editor and old crontab could be pasted/typed there. Not script friendly way...

I tried fcrontab -c backup.crontab but I see many errors on the output, fcrontab doesn't like the file format... And there are some complains about file permissions and ownership (chmod 600 backup.crontab; chown root:cron backup.crontab; fcrontab -c backup.crontab) - this is wrong; fcrontab -c reads configuration file, that is why it complains about errors

Summary is that it is easy to delete current crontab but not so easy to restore it from a file... :-(

yo8192 commented 4 months ago

fcrontab -r behaves like the traditional Vixie cron: crontab -r doesn't ask for confirmation. I appreciate that people have to be careful, and yes if there was no prior art I agree that asking for confirmation would be good (with a command line option to skip confirmation). But I'd rather stay consistent with the original cron whenever possible, including on this. Keeping backups of whatever you change on your systems, including fcrontab configs, is obviously a good idea.

As for your question, you simply need to run fcrontab backup.crontab -- careful: if you already had a fcrontab, that will replace it without confirmation.