
Untitled
By: a guest on
May 10th, 2012 | syntax:
None | size: 0.86 KB | hits: 15 | expires: Never
loop next if fail
h=%w"host1 host2 host3 host4"
h.each do |hostname|
tn = Net::Telnet::new("Host" => "#{hostname}",
"Timeout" => false,
"Prompt" => /[$%#>] z/n)
tn.cmd('String' =>'user' , 'Match'=>/Password:/) { |c| puts c }
tn.cmd('String' =>'password', 'Match'=>/#/) { |c| puts c }
tn.cmd('String' =>"show run | redirect tftp://192.1.1.1/#{hostname}-#{tdate}.cfg", 'Match'=>/#/) { |c| puts c }
sleep(3)
end
begin
tn = Net::Telnet::new("Host" => "#{hostname}",
"Timeout" => false,
"Prompt" => /[$%#>] z/n)
rescue => e
puts "Unable to connect to #{hostname}: #{e.message}"
next
end
tn = Net::Telnet::new(:host => "#{hostname}",
:timeout => false,
:prompt => /[$%#>] z/n)