0

Hi I want to store output of a shell command into chef variable. 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  
Robert
  • 10,403
  • 14
  • 67
  • 117
user3382084
  • 1
  • 1
  • 1
  • What do you mean "store"? Are you trying to get the version of nginx? That should be exposed via the nginx ohai plugin. – sethvargo Mar 05 '14 at 06:15

1 Answers1

1

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

Version without parentheses should work too

current_version = `#{node['kayako_nginx']['prefix']}/sbin/nginx -v | grep -Eo "\d+\.\d+\.\d+"`
user3356885
  • 391
  • 2
  • 6