Hi,
New to ruby but have used it alot in the last year to ssh into multiple
servers to run commands and ftp files to remote servers as well.
Current issue is that I am read a file into an array which I have done.
Now I want to pull information out of the array by comparing it to
another array.
for each item in the list array, I would like to pull the line out of
the lines array.
#!/usr/bin/env ruby
require ‘io/console’
list = [‘host_name’, ‘service_description’, ‘active_checks_enabled’,
‘notifications_enabled’]
lines = IO.readlines("/home/download/status.dat")
puts lines.length
lines.each do |line|
if line == list
puts line
end
end
I try that but get no results but know that each one of items in list is
in the array lines.
Below is a example of what is in the file.
host_name=10.10.10.11
active_checks_enabled=1
notifications_enabled=1
service_description=Users_Total_OS_22980
#!/usr/bin/env ruby
require ‘io/console’
list = [‘host_name’, ‘service_description’, ‘active_checks_enabled’,
‘notifications_enabled’]
lines = IO.readlines("/home/download/status.dat")
puts lines.length
lines.each do |line|
puts line if list.any? {|a|a==line.chomp}
end
I try that but get no results but know that each one of items in list is
in the array lines.
Below is a example of what is in the file.
host_name=10.10.10.11
active_checks_enabled=1
notifications_enabled=1
service_description=Users_Total_OS_22980
lines.each do |line|
field_name=line.chomp.split(’=’).first.strip
puts line if list.any? {|a|a==field_name}
end