in reply to Problems with Cisco Router Perl Query
One big problem with your code is that it does no error checking.
You should check for errors when you "open DEVICE", and check for a valid $session when it is opened.
Most importantly, you should check for a non-zero return value from $session->login, and bail, if that fails.
open (my $DEVICE, "<", 'device.list') or die "Could not open device li +st:$!"; while (<$DEVICE>) { chomp; my $routerIP = $_; print "Router IP is $routerIP,"; my $session = Net::Telnet::Cisco->new(Host => "$routerIP", Input_log +=>"input.log", ); if (! $session){ warn "Could not open session to $routerIP\n"; next; } if (! $session->login("$username", "$password") ){ warn "Could not login to $routerIP\n"; next; } my @output = $session->cmd("$cmd"); .... process ... }
Profanity is the one language all programmers know best.
|
|---|