如何禁用crontab -l中的所有内容?

我只想暂停一切。 不要执行crontab -l上列出的任何东西。

crontab -e然后注释掉你不想用#运行的每一行。

首先,备份crontab:

 crontab -l > my_cron_backup.txt 

那么你可以清空它:

 crontab -r 

恢复:

 crontab my_cron_backup.txt crontab -l 

你有root权限吗? 只要暂停cron

 sudo /etc/init.d/crond stop 

然后在准备就绪后重新启动它

 sudo /etc/init.d/crond start 

如果您使用vi作为编辑器,则只需在命令模式中input:%s/^/#/ 。 在所有行(%)中,用(#)替代(s ///)行(^)的开头。

对上面的选项不满意,因为它们不是一行。

禁用 crontab -l | perl -nle 's/^([^#])/# $1/;print' | crontab crontab -l | perl -nle 's/^([^#])/# $1/;print' | crontab

启用 crontab -l | perl -nle 's/^#\s*([0-9*])/$1/;print' | crontab crontab -l | perl -nle 's/^#\s*([0-9*])/$1/;print' | crontab

使用示例(编辑显示它不禁用注释)

 $ 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 

在RHEL和AIX上进行了testing,并且应该在没有任何需要安装的情况下运行

在我有限的testing中,将shell设置为/ bin / false工作。 你仍然会看到/opt/job.sh在你的日志中执行,但是这将是一个noop:

 SHELL=/bin/false */1 * * * * root /some/job.sh 

在我知道的任何Unix / Linux的味道:

 mv /var/spool/cron /var/spool/cron_is_disabled 

这个:

  • 禁用所有用户的crontabs
  • 但不是系统/ etc / crontab(/etc/cron.daily等)
  • 坚持重新启动
  • 是一个class轮,嗯:)

我从@segaps提供的答案中得到了这个想法

禁用:

 crontab -l | awk '{print "# "$1}' | crontab 

启用:

 crontab -l | cut -c 3- | crontab 

segaps提供的解决scheme唯一的问题是它将取消已经由用户评论的作业。