被Bash /壳牌启用crontab的/禁用任务 [英] Enable/Disable tasks in Crontab by Bash/Shell

查看:134
本文介绍了被Bash /壳牌启用crontab的/禁用任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来启用和禁用使用bash /壳牌crontab的任务?

因此​​,当用户开始服务器1,它可使服务器1 crontab的线等。
并且当用户停止服务器1,在服务器1 crontab的线获得禁用(#)。
这是可能的,怎么了?

在此先感谢

  * / 1 * * * *服务器1检查
* / 1 * * * *服务器2检查
* / 1 * * * *服务器3检查


解决方案

  SERVERNUM = $ 1

要启用:

 的crontab -l | SED/^#.*Server $ SERVERNUM支票/ S / ^#//| crontab中 - 

要禁用:

 的crontab -l | SED/^[^#].*Server $ SERVERNUM支票/ S / ^ /#/| crontab中 - 

成绩单:

  barmar @ $开发的crontab -l
* / 1 * * * *服务器1检查
* / 1 * * * *服务器2检查
* / 1 * * * *服务器3检查
barmar @ $开发的crontab -l | SED/^[^#].*Server 1支票/ S / ^ /#/'| crontab中 -
barmar @ $开发的crontab -l
#* / 1 * * * *服务器1检查
* / 1 * * * *服务器2检查
* / 1 * * * *服务器3检查
barmar @ $开发的crontab -l | SED/^#.*Server 1支票/ S / ^#//'| crontab中 -
barmar @ $开发的crontab -l
* / 1 * * * *服务器1检查
* / 1 * * * *服务器2检查
* / 1 * * * *服务器3检查

Is there a way to enable and disable Crontab tasks using Bash/Shell?

So when the user starts Server 1, it will enable the Server 1 Crontab line and so on. And when the user stops Server 1, the Server 1 Crontab line get disabled (#). Is this possible and how?

Thanks in advance

*/1 * * * * Server 1 check
*/1 * * * * Server 2 check
*/1 * * * * Server 3 check

解决方案

SERVERNUM=$1

To enable:

crontab -l | sed "/^#.*Server $SERVERNUM check/s/^#//" | crontab -

To disable:

crontab -l | sed "/^[^#].*Server $SERVERNUM check/s/^/#/" | crontab -

Transcript:

barmar@dev$ crontab -l
*/1 * * * * Server 1 check
*/1 * * * * Server 2 check
*/1 * * * * Server 3 check
barmar@dev$ crontab -l | sed '/^[^#].*Server 1 check/s/^/#/' | crontab -
barmar@dev$ crontab -l
#*/1 * * * * Server 1 check
*/1 * * * * Server 2 check
*/1 * * * * Server 3 check
barmar@dev$ crontab -l | sed '/^#.*Server 1 check/s/^#//' | crontab -
barmar@dev$ crontab -l
*/1 * * * * Server 1 check
*/1 * * * * Server 2 check
*/1 * * * * Server 3 check

这篇关于被Bash /壳牌启用crontab的/禁用任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆