Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在crontab中注释包含my_字符串的行_Cron_Crontab - Fatal编程技术网

在crontab中注释包含my_字符串的行

在crontab中注释包含my_字符串的行,cron,crontab,Cron,Crontab,为了管理停电,在我的crontab中,我想自动执行以下任务:“对包含我的_字符串的行进行注释”。 然后,使用另一个命令(或脚本)删除这些注释 谢谢大家! 我想,您想编写一个脚本,注释掉文件/etc/crontab中的一些行,并且您在一个类似Linux的环境中:对吗 发出下一个命令: sudo sed -i /etc/crontab -e '/my_string/s/^/#/' 要删除评论,请发布: sudo sed -i /etc/crontab -e '/my_string/s/^#//'

为了管理停电,在我的crontab中,我想自动执行以下任务:“对包含我的_字符串的行进行注释”。 然后,使用另一个命令(或脚本)删除这些注释


谢谢大家!

我想,您想编写一个脚本,注释掉文件/etc/crontab中的一些行,并且您在一个类似Linux的环境中:对吗

发出下一个命令:

sudo sed -i /etc/crontab -e '/my_string/s/^/#/'
要删除评论,请发布:

sudo sed -i /etc/crontab -e '/my_string/s/^#//'

在此之后,您无需重新启动cron服务。

多亏了Pierre et我的朋友Wildemar,这里有一个方法:

发表评论 crontab-l | sed'/my_string/s/^/#/'>cron_temp crontab cron_temp rm cron_temp

删除注释 crontab-l | sed'/my_string/s/#/'>cron_temp crontab cron_temp
rm cron_temp

非常感谢,但我正在使用Solaris,我的sed只有-e-f和-n选项。也许我需要使用一个临时文件实际上,你需要一个临时文件。