|
Posted by Mike D on November 8, 2004, 3:58 pm
Please log in for more thread options
I have been struggling with getting the waitfor method to return
values in a list context. No matter if I a looking for a list or a
scalar, the waitfor method returns 0 or 1. I am connecting to a Cisco
device, I can login, run commands via the cmd subroutine, and exit; I
just can't get waitfor to return what I need. Wondering if I am
missing something?
I know there is a Net::Telnet::Cisco module, but I will be using this
script for other devices as well.
Thanks in advance
-- snip --
my $session = new Net::Telnet(Timeout => 10);
my $ok = $session->open('xxx.xxx.xxx.xxx');
$session->waitfor('/name:.*/')
|| die "Did not get login promptn";
$session->print("USERNAME");
$session->waitfor('/word:.*/')
|| die "Did not get password promptn";
$session->print("PASSWORD");
my ($prematch,$match) = $session->waitfor('/Device/')
|| die "Did not get promptn";
$session->print("exit");
print "!$prematch!$match!n";
-- snip --
output:
Use of uninitialized value in concatenation (.) or string at
../test_Net_Telnet.pl line 33.
!1!!
|
|
Posted by Mike D on November 9, 2004, 7:24 am
Please log in for more thread options
midellan@chartermi.net (Mike D) wrote in message
> I have been struggling with getting the waitfor method to return
> values in a list context. No matter if I a looking for a list or a
> scalar, the waitfor method returns 0 or 1. I am connecting to a Cisco
> device, I can login, run commands via the cmd subroutine, and exit; I
> just can't get waitfor to return what I need. Wondering if I am
> missing something?
>
> I know there is a Net::Telnet::Cisco module, but I will be using this
> script for other devices as well.
>
> Thanks in advance
>
> -- snip --
>
> my $session = new Net::Telnet(Timeout => 10);
>
> my $ok = $session->open('xxx.xxx.xxx.xxx');
>
> $session->waitfor('/name:.*/')
> || die "Did not get login promptn";
> $session->print("USERNAME");
>
> $session->waitfor('/word:.*/')
> || die "Did not get password promptn";
> $session->print("PASSWORD");
>
> my ($prematch,$match) = $session->waitfor('/Device/')
> || die "Did not get promptn";
>
> $session->print("exit");
>
> print "!$prematch!$match!n";
>
> -- snip --
>
> output:
> Use of uninitialized value in concatenation (.) or string at
> ./test_Net_Telnet.pl line 33.
> !1!!
Nevermind, I figured it out.
The solution is to change the "||" to "or". Seems to be a precedance
problem between the "=" and the "||".
So:
my ($prematch,$match) = $session->waitfor('/Device/')
|| die "Did not get promptn";
would be changed to:
my ($prematch,$match) = $session->waitfor('/Device/')
or die "Did not get promptn";
|
| Similar Threads | Posted | | How do you telnet from 1 host to another using Telnet Module | December 21, 2005, 4:15 pm |
| net::telnet to ms telnet server | May 19, 2005, 12:28 am |
| Net::Telnet | December 9, 2004, 11:33 pm |
| NET::Telnet | February 15, 2006, 8:42 am |
| Net::telnet | June 9, 2006, 1:42 am |
| net::telnet problem | July 23, 2004, 6:46 pm |
| Telnet from perl | September 23, 2004, 2:12 pm |
| Help for Net::Telnet Module | December 5, 2004, 11:30 pm |
| Net::Telnet and SMTP | June 13, 2005, 11:01 am |
| Problem with Net::Telnet | October 20, 2005, 4:19 pm |
|