Read files on a remote server

Hi all,

I’m pretty much new to Ruby world and trying to write a program to
read files on a remote server and parse them locally. I don’t see
examples online running Methods or Modules using SSH. Can anyone please
provide some idea/info?

I’m trying to parse “/etc/sysctl.conf” file and pull the parameter
values from several servers.

module DeCommenter
def self.decommenter(infile, outfile, comment_re = /\A\s*#/)
infile.each do |inline|
unless inline =~ comment_re || inline.gsub("\n",’’).length == 0
parameter, value = inline.chomp.split(’ = ')
outfile.puts inline
end
end
end
end

Logon to server and parse file using the above module.
File.open(“system.txt”) do |f| #Reading file for host,password details
while record = f.gets
include DeCommenter
@hostname, @password = record.chomp.split(’ => ')
puts “hostname #{@hostname}, password #{@password}, username
#{@username}”
begin
ssh = Net::SSH.start(@hostname, @username, :password =>
@password) do |session|
puts “I’m on the server #{@hostname} using
#{@username}/#{@password}”
shell = session.shell.open
end
end
end

Thanks,
Satish