Hello Monks,
Should be a simple answer for anyone with more than the week's worth of knowledge I possess. So I'm trying to create a small script to have users telnet into their selected devices. The problem I'm running into is getting the device entered to work in Net::Telnet.
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;
print "Enter your device: ";
my $device = <STDIN>;
my $telnet = new Net::Telnet (Timeout=>15
,Input_log => "received_data.txt"
);
$telnet->open($device);
$telnet->waitfor('/username: /i');
$telnet->print('xxxx');
$telnet->waitfor('/password: /i');
$telnet->print('xxxx');
$telnet->waitfor('/$device"."# /i'); ##wait for prompt
$telnet->print ('show run');
$telnet->print('exit');
my $out = $telnet->waitfor('/$device"."# /i');
print $out;
$telnet->close();
my $fname = "received_data.txt";
open (my $fh, "<", $fname) or die "Can't open";
while (<$fh>) {
print if /ip prefix-list/;
}
This is the error I'm getting:
bad match operator: Global symbol "$device" requires explicit package name at telnet3.pl line 23 .
I'm just having trouble figuring out why $device is coming up not defined and if their is a way to get this to work.
Uncaught exception from user code:
bad match operator: Global symbol "$device" requires explicit package name <STDIN> line 7. at scopedzT1 line 279
at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm line 2036
Net::Telnet::_croak('Net::Telnet=GLOB(0x372ae8)', 'bad match operator: Global symbol "$device" requires explicit...') called at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm line 539
Net::Telnet::error('Net::Telnet=GLOB(0x372ae8)', 'bad match operator: Global symbol "$device" requires explicit...') called at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm line 2478
Net::Telnet::_match_check('Net::Telnet=GLOB(0x372ae8)', '/$device "."# /i') called at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm line 2002
Net::Telnet::waitfor('Net::Telnet=GLOB(0x372ae8)', '/$device "."# /i') called at scopedzT1 line 279