简体   繁体   English

sed和regex修改crontab

[英]sed and regex to modify crontab

I'm stuck on a problem when I'm trying to modify a crontab entry with sed and regex. 当我尝试使用sed和regex修改crontab条目时遇到问题。

Content of the crontab : crontab的内容:

40 09 21 02 * cd /toto/tata && ./script.sh  1>../log/script_customer1.log 2>../log/script_customer1.err #customer1 #type1 #editable
00 19 21 05 * cd /toto/tata && ./script.sh  1>../log/script_customer2.log 2>../log/script_customer2.err #customer2 #type1 #editable

My script : 我的剧本:

cust_hrt="#customer1 #type1"
crontab -l | sed -e 's/\([0-9]*\) \([0-9]*\) \([0-9]*\) \([0-9]*\) \(.*${cust_hrt} #editable\)/30 22 25 05 \5/'

but it doesn't work. 但这不起作用。 If I try directly with: 如果我直接尝试:

crontab -l | sed -e 's/\([0-9]*\) \([0-9]*\) \([0-9]*\) \([0-9]*\) \(.*#customer1 #type1 #editable\)/30 22 25 05 \5/'`

then it works. 然后就可以了。

I don't understand. 我不明白 Did I miss something with the variable ? 我是否错过了一些变量?

The variable inside single quotes isn't interpolated. 单引号内的变量不会插值。 It should work if you switch to using double quotes for your sed command. 如果您切换到对sed命令使用双引号,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM