Use Net::SSH Error

I have a script that login to few remote servers and runs few
commands.Need to add some code in that if script gets a error and can’t
login to one of the hosts then it will print something out then move on
to next host and run the commands and so on until it reach end of
script.

#!/usr/bin/env ruby
require ‘rubygems’
require ‘net/ssh’

USER = ‘root’
PASS = ‘rootroot’
hosts = [‘host1’,
‘host2’,
‘host3’,
‘host4’, ]

cmd = [‘hostname’,
‘mysql-cluster-show’,
‘df -h’,
‘service rsyslog status’,
“echo ‘*** *’",
"echo '
****’”,]

hosts[0…3].each do |host|
Net::SSH.start( host, USER, :password => PASS ) do |ssh|
for cmds in cmd[0…6].each
result = ssh.exec! cmds
puts result
end
end
end