What is the best way to add and remove a hash symbol (#) from the crontab? I’d like to have a one liner that is capable of commenting all the cronjobs at once and if needed, uncomment them. It’s a CentOS distro.
I think the best option is to use ‘sed’ but I’m not entirely sure how it’d work with the crontab.
thanks.
You could do something like
sed -e 's/^#//g' -i /etc/crontab…sed -e 's/^/#/g' -i /etc/crontab— assuming that your crontab file has no actual comments in it.Safer to use a sentinel like
s/^/#disabled: /g&s/^#disabled: //gEven safer to put the “affected” cron entries into a file in
/etc/cron.d/and move that file in/out of the directory as-needed.mv /usr/local/etc/special-cron-jobs /etc/cron.d/;mv /etc/cron.d/special-cron-jobs /usr/local/etcIf you’re just trying to disable them all, you could also just stop
cronitself, using(*
anacronmay not be right on CentOS?)