0

I'm trying to extend an existing cookbook where we use Mixlib::ShellOut to collect a fair amount of information about an Oracle install. Mostly it just works.

I'm trying to add a node attribute for where TFA is running - because that can vary depending on version. From the server itself, a simple ps -ef | grep tfa | grep java | awk '{print $NF}' gives me exactly what I need.

When I add that to the recipe as

tfa_home = ::Mixlib::ShellOut.new("ps -ef | grep tfa | grep java | awk '{print $NF}'")
tfa_home.run_command
node.normal['gbucs_oracledb']['orahome']['tfa_home'] = tfa_home.stdout.strip

The resulting output json seems to get a newline char as well as the string "$NF'":

"tfa_home": "/u01/app/19.0.0.0/grid/tfa/<hostname>/tfa_home\n$NF}'"

I've tried a couple variants of escaping the $NF, but no luck so far. Is there an obvious solution?

stephan
  • 45
  • 1
  • 8

1 Answers1

1

What about String.gsub ?

tfa_home.stdout.strip.gsub(/\n\$NF}'/, '')
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
  • I ended up using `tfa_home.stdout.strip.gsub(/[\n\$NF}']/,'')`. Thank you so much - this was driving me crazy! – stephan Jun 11 '20 at 20:21
  • `/[\n\$NF}']/` - will find occurrences of each 1 symbol in the square brackets. I bet you don't want to replace _any_ N, F, } and ' with nothing. – Draco Ater Jun 12 '20 at 06:26