In the foreach loop, it prints off the expected results (the names that match $hostregex) and until I added the
my @version = $session->cmd('show version ');
line, it appeared to go to the switch in question.
When I added
my @version = $session->cmd('show version ');
I get the following error:
myname@bast1:~/bin$ testloop 101a Global symbol "$session" requires explicit package name at /home/mynam +e/bin/testloop line 31. Execution of /home/myname/bin/testloop aborted due to compilation erro +rs. myname@bast1:~/bin$
Here's the script. Any help would really be appreciated.
#!/usr/bin/perl use Net::Telnet::Cisco ; use strict; #always and forever, amen. use warnings; #or else. use lib '/home/myname/bin/lib'; use subs ; if ($#ARGV != 0) { print "usage: enter the switchname \n"; exit; } my $hostregex = $ARGV[0] ; my $infile = "/home/myname/zen/zen_devices_out" ; # print "You're using: '$infile'\n\n" ; open INF , "$infile" or die $! ; my @lines = <INF> ; my @matches = (grep(/$hostregex/i,@lines)) ; foreach (@matches) { chomp($_) ; print "'$_'\n" ; my ( $p1 , $p2 ) = get_p() ; my $session = Net::Telnet::Cisco->new(Host => $_); $session->login('myname', $p1); if ($session->enable($p2) ) { } else { warn "Can't enable: + " . $session->errmsg; } } my @version = $session->cmd('show version '); print @version ; exit ;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |