Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. loop next if fail
  2. h=%w"host1 host2 host3 host4"
  3.  
  4. h.each do |hostname|
  5.  
  6.   tn = Net::Telnet::new("Host" => "#{hostname}",
  7.                                "Timeout" => false,
  8.                                "Prompt" => /[$%#>] z/n)
  9.  
  10.   tn.cmd('String' =>'user' , 'Match'=>/Password:/) { |c| puts c }
  11.   tn.cmd('String' =>'password', 'Match'=>/#/) { |c| puts c }
  12.  
  13.  
  14.       tn.cmd('String' =>"show run | redirect tftp://192.1.1.1/#{hostname}-#{tdate}.cfg", 'Match'=>/#/) { |c| puts c }
  15.       sleep(3)
  16.  
  17.  
  18. end
  19.        
  20. begin
  21.   tn = Net::Telnet::new("Host" => "#{hostname}",
  22.                         "Timeout" => false,
  23.                         "Prompt" => /[$%#>] z/n)
  24. rescue => e
  25.   puts "Unable to connect to #{hostname}: #{e.message}"
  26.   next
  27. end
  28.        
  29. tn = Net::Telnet::new(:host    => "#{hostname}",
  30.                         :timeout => false,
  31.                         :prompt  => /[$%#>] z/n)