well i've found and pieced together a script (mainly found; i'm very new to perl) to scan a group of cisco switches that i have and print information out in a text file. everything seems to work pretty well except when a particular cmd doesn't apply to one of the switches listed in my infile. the script seems to get stuck in these instances and closes without going to the next valid switch. maybe i need some sort of ELSE type of statement or something?? here's the basic script that i've been using(searchall .txt is just a list of IP addresses):
use Net::Telnet::Ci sco;
open(OUTFILE, ">allrslts.doc" );
$start = localtime;
print OUTFILE "TIME OF REPORT $start\n\n";
open(INFILE, "searchall.txt" ) or die "Can't open searchall.txt: $!";
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::Ci sco->new(Host => $line, timeout => "$timeout1" );
###ENTER USERNAME AND PASSWORD INFO BELOW
$session1->login('USERNAM E', 'PASSWORD');
###ENTER ENABLE PASSWORD AND CISCO CMD BELOW
if ($session1->enable('PASSWO RD') ) {
my @output = $session1->cmd('CISCO_CMD ');
print OUTFILE "@output \n\n";
print @output;
} else {
warn "Can't enable: " . $session1->errmsg;
}
$session1->close;
}
close INFILE;
close OUTFILE;
use Net::Telnet::Ci sco;
open(OUTFILE, ">allrslts.doc" );
$start = localtime;
print OUTFILE "TIME OF REPORT $start\n\n";
open(INFILE, "searchall.txt" ) or die "Can't open searchall.txt: $!";
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::Ci sco->new(Host => $line, timeout => "$timeout1" );
###ENTER USERNAME AND PASSWORD INFO BELOW
$session1->login('USERNAM E', 'PASSWORD');
###ENTER ENABLE PASSWORD AND CISCO CMD BELOW
if ($session1->enable('PASSWO RD') ) {
my @output = $session1->cmd('CISCO_CMD ');
print OUTFILE "@output \n\n";
print @output;
} else {
warn "Can't enable: " . $session1->errmsg;
}
$session1->close;
}
close INFILE;
close OUTFILE;
Comment