Hello all,
just want to clarify a little. when i run a perl script to gather information from a group of cisco switches that i maintain and the switch doesnt respond or the cmd is invalid the script just times out instead of going to the next IP address/switch in the list to gather information. does anyone know how to prevent this from aborting? here's more or less the script that i've been running:
#!perl -w ###(yea, unfortunately i'm running this on a windows machine...oh well)
use Net::Telnet::Cisco;
use Net::Telnet::Cisco;
open(OUTFILE, ">flr3rslts.doc");
$start = localtime;
print OUTFILE "TIME OF REPORT $start\n\n";
open(INFILE, "flr3list.txt") or die "Can't open flr3list: $!";
while (<INFILE>) { # assigns each line in turn to $_
print "$_";
$line = <INFILE>;
print "IP ADDRESS $line\n";
print OUTFILE " IP ADDRESS $line\n";
$timeout1 = ("30");
$session1 = Net::Telnet::Cisco->new(Host => $line, timeout => "$timeout1");
while (<INFILE>) { # assigns each line in turn to $_
print "$_";
$line = <INFILE>;
print "IP ADDRESS $line\n";
print OUTFILE " IP ADDRESS $line\n";
$timeout1 = ("30");
$session1 = Net::Telnet::Cisco->new(Host => $line, timeout => "$timeout1");
###########Login, enable, and run cmd
$session1->login('username', 'password') or die "Unable to login: $!";
if ($session1->enable('password') ) {
my @output = $session1->cmd('a cisco cmd such as show mod');
print OUTFILE "@output \n\n";
print @output;
} else {
warn "Can't enable: " . $session1->errmsg;
}
$session1->close;
}
close INFILE;
close OUTFILE;
The flr3list.txt INFILE is just a list of IP addresses that the script uses to telnet in to my Cisco switches. This script, although I'm sure is full of at least minor errors, seems to work great for the most part. The one major downfall is that when a particular cisco switch is down or doesn't support the cmd I'm running (ie. 'sho mod' is only a valid cmd on modular switches) the script gets "stuck" for a moment and then closes instead of trying the next switch/IP on the list. Thanks for any advice you may have.
Jason
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
