Use sed to edit crontab

后端 未结 2 1480
余生分开走
余生分开走 2021-01-19 19:12

I am writing a sed command that should uncomment an entry in crontab. Is there a better way to do this? The first option that comes to mind is sed.

Example:

2条回答
  •  时光说笑
    2021-01-19 20:07

    Whether using sed or other tool whould not make much a difference. I'd use sed also.

    But to properly modify what cron is using, please mind to use crontab command.
    Do NOT try just editing the data file (e.g. /etc/crontab on some systems). Cron won't pick up the changes!!!.

    You might use a pipe:

    crontab -l | sed -e "s#\# 5 \* \* \* 3 bash test.sh#5 * * * 3 bash test.sh#"| crontab 
    

    to perform the change.

    Nevertheless, would it not just be simpler to add the functionality of enabling/disabling into the script being run?

提交回复
热议问题