How to disable everything in crontab -l?
Solution 1:
First, back up the crontab:
crontab -l > my_cron_backup.txt
Then you can empty it:
crontab -r
To restore:
crontab my_cron_backup.txt
crontab -l
Solution 2:
crontab -e
then comment out each line you don't want to run with #
.
Solution 3:
Do you have root access? Just pause cron
sudo /etc/init.d/crond stop
Then restart it when you're ready
sudo /etc/init.d/crond start
Solution 4:
If you are using vi as editor, then just enter :%s/^/#/
in command mode. In all lines (%), it substitutes (s///) the begin of line (^) with a hash (#).
Solution 5:
Wasn't happy with the options above since they weren't one liners.
To disable crontab -l | perl -nle 's/^([^#])/# $1/;print' | crontab
To enable crontab -l | perl -nle 's/^#\s*([0-9*])/$1/;print' | crontab
usage example ( edited to show it doesn't disable comments)
$ crontab -l
# Comment
0 0 * * 0 /opt/something.sh
$ crontab -l|perl -nle 's/^([^#])/# $1/;print'|crontab
$ crontab -l
# Comment
# 0 0 * * 0 /opt/something.sh
$ crontab -l|perl -nle 's/^#\s*([0-9*])/$1/;print'|crontab
$ crontab -l
# Comment
0 0 * * 0 /opt/something.sh
Tested this on RHEL and AIX , and should work out of the box without anything needed to be installed