Disable crontab's remove option in CLI
I suggest that you include
alias crontab="crontab -i"
in your ~/.bashrc
file (start a new shell before testing!)
This means that every time you run crontab, you always select the "-i" option. If you now give the crontab -r
command, it is processed at crontab -ir
, which prompts before removing the crontab file:
nick@serv2:~$ crontab -r
crontab: really delete nick's crontab? (y/n) n
Use a wrapper around the crontab
command, for example this function would do:
crontab () { [[ $@ =~ -[iel]*r ]] && echo '"r" not allowed' || command crontab "$@" ;}
This function checks if -r
exists in the argument of crontab
; if so, exits with the message "r" not allowed
, otherwise executes the command.
Put it in your ~/.bashrc
to get it loaded upon initialization of all interactive bash
sessions.