【问题标题】:How to enable and disable cronjobs using shell script如何使用 shell 脚本启用和禁用 cronjobs
【发布时间】:2017-06-27 03:07:44
【问题描述】:

我们想启用/禁用以下 crontab:

*/1 * * * * bash /home/scripts/mywork.sh

已经尝试禁用 using(看起来我用那个 :/ 清除了我的 crontabs):

crontab -l | sed "/^[^#].*bash /home/scripts/mywork.sh/s/^/#/" | crontab -

...并解决问题:

sed: -e expression #1, char 16: extra characters after command

如何解决? :)

我是 stackoverflow 的新手,请随时发表评论,以便提高我的提问技巧。

【问题讨论】:

    标签: bash shell cron


    【解决方案1】:

    您必须在 sed 命令中转义“/”字符...

    sed "/^[^#].*bash \/home\/scripts\/mywork.sh/s/^/#/"
    

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 2014-03-11
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      相关资源
      最近更新 更多