errs = []
def test_server(errs, server)
lambda do |options|
begin
server =~ /(.+)@(.+)/
server_name, user = $2, $1
puts server_name
s = Net::SSH.start(server_name, user)
s.close
s = server
rescue Errno::EHOSTUNREACH, SocketError
puts "echec connexion #{server} : #{$!}"
errs << server
s = nil
end
return s
end
end
Net::SSH::Multi.start(:on_error => :warn) do |session|
session.use &test_server(errs, 'root@srv-04')
session.use &test_server(errs, 'root@srv-07')
session.use &test_server(errs, 'root@srv-08')
session.use &test_server(errs, 'root@fail-08.local')
session.exec( "hostname" )
session.loop
end
unless errs.empty?
puts "The command failed on #{errs.size} hosts"
end