Results 1 to 2 of 2
Apr 21, 2009, 04:47 #1
- Join Date
- Mar 2009
- 0 Post(s)
- 0 Thread(s)
Error Handling for SSH Connection
I'm trying to figure out how to handle exceptions brought up by starting an SSH connection that fails.
For example, I have this code
$arrConnInfo.each do |strConnInfo| strConnInfo = strConnInfo.split(",") # Load connection variables strHostName = strConnInfo strUserName = strConnInfo strUserPwd = strConnInfo begin Net::SSH.start( strHostName, strUserName, strUserPwd ) do |session| shell = session.shell.sync $a = LinuxSystem.new(shell) end rescue SocketError puts "Host name cannot be resolved." break end #work with SSH connection here if connection is successful.... end
Right now, if the SocketError exception is brought up, it hits break and the program stops. How can I code it so it will simply move on to the next iteration? I don't find much information on the break method, so are there any alternatives?