SDN has asked for the wisdom of the Perl Monks concerning the following question:
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.
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
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.#!/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/; }
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with Net::Telnet
by frozenwithjoy (Priest) on Nov 25, 2012 at 23:03 UTC | |
by SDN (Initiate) on Nov 26, 2012 at 00:34 UTC | |
by frozenwithjoy (Priest) on Nov 26, 2012 at 01:36 UTC | |
by SDN (Initiate) on Nov 26, 2012 at 03:42 UTC | |
by frozenwithjoy (Priest) on Nov 26, 2012 at 05:37 UTC | |
by aitap (Curate) on Nov 26, 2012 at 17:21 UTC | |
Re: Problem with Net::Telnet
by jrogers (Initiate) on Nov 26, 2012 at 14:29 UTC | |
by SDN (Initiate) on Nov 27, 2012 at 14:57 UTC |
Back to
Seekers of Perl Wisdom