linux-puppet onlyif with pgrep不起作用
发布时间:2020-12-14 02:42:27 所属栏目:Linux 来源:网络整理
导读:我想在puppet中使用exec,只要它的进程没有运行 exec { "execute me": onlyif = "pgrep -fc 'ruby execute.rb'",command = "execute me",} 所以在上面的例子中,如果进程’ruby execute.rb’已经运行,那么exec不应该运行为 pgrep -fc 'ruby execute.rb' will r
我想在puppet中使用exec,只要它的进程没有运行
exec { "execute me": onlyif => "pgrep -fc 'ruby execute.rb'",command => "execute me",} 所以在上面的例子中,如果进程’ruby execute.rb’已经运行,那么exec不应该运行为 pgrep -fc 'ruby execute.rb' will return 1. 然而 该命令似乎总是在木偶中运行. 在我的linux框中,当我执行pgrep -fc’ruby execute.rb’时,我总是得到一个大于0的值. 我的命令有问题吗? 解决方法
只有当pgrep返回0时,你的exec才会运行.pgrep手册页告诉我们,只有找到匹配的进程时,pgrep的退出代码才为零(0),当没有匹配的进程时,它将返回一(1).另一方面,puppet文档告诉我们,只有当参数中的命令返回0时,parameter onlyif才会执行资源.
而不是只有你应该使用parameter unless.这样你的exec只会在你的pgrep返回非零时运行,即.它没有找到任何匹配的过程. exec { "execute me": unless => "pgrep -fc 'ruby execute.rb'",} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |