[英]sed and regex to modify crontab
当我尝试使用sed和regex修改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
我的剧本:
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/'
但这不起作用。 如果我直接尝试:
crontab -l | sed -e 's/\([0-9]*\) \([0-9]*\) \([0-9]*\) \([0-9]*\) \(.*#customer1 #type1 #editable\)/30 22 25 05 \5/'`
然后就可以了。
我不明白 我是否错过了一些变量?
单引号内的变量不会插值。 如果您切换到对sed命令使用双引号,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.