[英]store shell command output to ruby variable or chef
Hi I want to store output of a shell command into chef variable. 嗨,我想将shell命令的输出存储到Chef变量中。 I have seen some way but not able to get how to do it. 我已经看到了一些方法,但是无法获得如何做的方法。
Here is what I have tried so far 到目前为止,这是我尝试过的
current_version = `#{node['kayako_nginx']['prefix']}/sbin/nginx -v | grep -Po "(\d+\.\d+\.\d+)"`
print "cheking version of nginx #{current_version}"
it is executing command but not storing it 它正在执行命令但不存储它
this is the output while executing chef 这是执行厨师时的输出
nginx version: nginx/1.5.3
cheking version of nginx
Most probably you have a problem in your first string. 最有可能您的第一个字符串有问题。 Try it like this 像这样尝试
current_version = `#{node['kayako_nginx']['prefix']}/sbin/nginx -v | grep -Eo "(\d+\.\d+\.\d+)"`
grep options have changed to -Eo
grep选项已更改为-Eo
Version without parentheses should work too 没有括号的版本也应该工作
current_version = `#{node['kayako_nginx']['prefix']}/sbin/nginx -v | grep -Eo "\d+\.\d+\.\d+"`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.