Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: Cisco Telnet

by McA (Priest)
on Aug 19, 2013 at 11:30 UTC ( #1050018=note: print w/replies, xml ) Need Help??

in reply to Re^2: Cisco Telnet
in thread Cisco Telnet


In Re: Cisco Telnet ~~David~~ is showing you how to wrap the call to login with an eval block to catch an exception. Then you are able to log that issue and proceed in your loop.

Is that what you meant?


Replies are listed 'Best First'.
Re^4: Cisco Telnet
by mvip (Acolyte) on Aug 21, 2013 at 05:51 UTC

    well no, and i try that eval procedure and it just gave me the error massage that is saying the router is down and can't connect and the script end. I need something that will tel me that and continue. For example if i have 100 routers and the script start from 1 and as he going on 2,3,4,5 ... (lets say that router 10 is down ) when he comes to router 10 to say i can't connect to this router, and to moves on, and that is router 11, 12, 13 ... not to stop and end. For now iv try eval procedure and with sub routines and iv got nothing ... and i need this because i have to set the same config and settings on almost 300 routers and some of them are down some of them are not that ip end etc.

      Please let me see the code you used the last time.


        Hi, here is what iv got ...

        use Net::Telnet::Cisco; #use strict; #use warnings; #use diagnostics; #use threads; my %users =("1" => "admin", "2" => "admin", "3" => "admin", "4" => "admin", "5" => "admin", "6" => "none", "7" => "admin", "8" => "admin", "9" => "admin", "10" => "admin", ); my %pwds = ("1" => "admin", "2" => "admin", "3" => "admin", "4" => "admin", "5" => "admin", "6" =>"s0m3th1ng", "7" => "admin", "8" => "admin", # not connected "9" => "admin", "10" => "admin", ); for ( $i = 1; $i<=10; $i++){ $device = "172.16.$i.251"; if ( $users{$i} eq "none" ) { my $curpwd = $pwds{$i}; my $session = Net::Telnet::Cisco->new(Host => "$device", Input_log => "perllogrouter/ro +uter$i.log", ); eval { $session->login(Password => $curpwd);}; if ($@) { print "Error: $@\n"; } else { if ($session->enable("$curpwd")) { # Execute a command @output = $session->cmd ('show running-config | section ho +stname'); print "@output\n"; print " ================================================== +====\n"; } $session->close; } } else { my $session = Net::Telnet::Cisco->new(Host => "$device", Input_log => "perllogrouter/ro +uter$i.log", ); eval {$session->login($users{$i}, $pwds{$i});}; if ($@) { print "Error: $@\n"; } else { # Execute a command @output = $session->cmd ('show running-config | section ho +stname'); print "@output\n"; print " ================================================== +====\n"; } } }

        I have note that if i have bad or wrong password the script continue but if i have Router that is not alive the script not continue it ends there ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050018]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2016-10-27 00:03 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (350 votes). Check out past polls.