hostList.each do |h| Net::SSH.start(h, "user", :password => "password", :timeout => 10) do |ssh| end end
However, my test script kept dying at various points due to issues with the ssh connection to specific servers.
Naturally I thought of wrapping the Net::SSH.start call in a begin/rescue/end but couldn't for the life of me find any information about the exceptions that the start method could throw. Finally after a bit of digging on google I came across this page which details them rather handily :-) In short, here's how I have it wrapped now:
hostList.each do |h|
begin
Net::SSH.start(h, "user", :password => "password", :timeout => 10) do |ssh|
end
rescue Timeout::Error
puts " Timed out"
rescue Errno::EHOSTUNREACH
puts " Host unreachable"
rescue Errno::ECONNREFUSED
puts " Connection refused"
rescue Net::SSH::AuthenticationFailed
puts " Authentication failure"
end
end
This works fabulously since I don't really need to handle the exceptions but would like to know about them.
This is just what I needed! Thank you.
ReplyDeleteI've come back to this post a few times myself :-) I'm glad you found it useful!
ReplyDeleteThanx, man!!! That is great! realy
ReplyDeleteMany thanks
ReplyDelete