Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'net/ssh/multi'
- HOSTLIST = ['132.0.0.1','127.0.0.1']
- USERLIST = ['user','user']
- PASSWORD = ['userpegase','userpegase']
- TIMEOUT = 3
- # Gérer les erreurs de connexion... On retente de se connecter 3 fois, après ça (si échec), on lève l'exception
- failConnectionHandler = Proc.new do |server|
- puts "Hello"
- server[:connection_attempts] ||= 0
- if server[:connection_attempts] < 3
- server[:connection_attempts] += 1
- throw :go, :retry
- else throw :go, :raise
- end
- end
- begin
- Net::SSH::Multi.start(:on_error => failConnectionHandler) do |session|
- HOSTLIST.each_with_index do |session_server,index|
- session.use session_server , :user => USERLIST[index] , :password => PASSWORD[index]
- puts session.to_s
- session.exec 'pwd' do |ch, stream, data|
- puts "[#{ch[session_server]} : #{stream}] - #{data}"
- end
- end
- session.loop
- end
- rescue Timeout::Error
- puts "Timed out"
- rescue Errno::EHOSTUNREACH
- puts "Host unreachable"
- rescue Errno::ECONNREFUSED
- puts "Connection refused"
- rescue Net::SSH::AuthenticationFailed
- puts "Authentification failure "
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement