Hi you Ruby Guru's
I have a small problem thats driving me crazy. I am trying to connect to
multiple ssh servers (1 at a time), run a number of commands and capture
the output to a unique file for each server.
My code looks like this :
-- snip --
require 'rubygems'
require 'net/ssh'
hosts = ['10.0.255.1' , '10.0.255.2' , '10.0.255.3']
instructions = [
'sh version',
'sh cdp ne'
]
hosts.each do |host|
Net::SSH.start(host, 'user', :password => 'password') do |ssh|
fn = File.open("output\/#{host}.txt", 'w')
instructions.each do |command|
fn.puts "|--------\[#{command}\]--------------------------"
fn.puts ssh.exec!(command)
end
fn.close
end
end
-- snip --
When I run this I get the following error :
Net::SSH::ChannelOpenFailed: (4)
If I remove the instructions.each loop and run only a single command. Life
is good and it all works. If I add a second ssh.exec! or the loop, the
error returns.
It appears that the ssh.exec! closes the connection. How do I keep it open
to allow me to run a second command?
Alan.