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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.