Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.81 KB | None | 0 0
  1. require 'rubygems'
  2. require 'net/ssh/multi'
  3.  
  4.  
  5. HOSTLIST = ['127.0.0.1','127.0.0.1']
  6. USERLIST = ['user','user']
  7. PASSWORD = ['userpegase','userpegase']
  8.  
  9.  
  10. Net::SSH::Multi.start(:on_error => :warn) do |session|
  11.                          
  12.   HOSTLIST.each_with_index do |session_server,index|
  13.     session.use session_server , :user =>  USERLIST[index] , :password => PASSWORD[index]
  14.   end
  15.  
  16.   begin
  17.     session.exec 'pwd' do |ch, stream, data|
  18.       puts "[#{ch[session]} : #{stream}] - #{data}"
  19.     end
  20.   rescue Timeout::Error  
  21.    puts "+++++++ Timed out"  
  22.   rescue Errno::EHOSTUNREACH  
  23.    puts "+++++++ Host unreachable"  
  24.   rescue Errno::ECONNREFUSED  
  25.    puts "+++++++ Connection refused"  
  26.   rescue Net::SSH::AuthenticationFailed  
  27.    puts "+++++++ Authentification failure "
  28.   end
  29.   session.loop
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement