1827207 Members
2553 Online
109716 Solutions
New Discussion

perl Net::Telnet problem

 
SOLVED
Go to solution
Gerald Bush_2
Occasional Advisor

perl Net::Telnet problem

I am having a hard time with the login phase of a perl scripted telnet session.

I have to be over looking something but for the life of me I don't know what it is. Here is the code:

my ($block, $filename, $host, $hostname, $k_per_sec, $line, $num_read,
$passwd, $prevblock, $prompt, $size_bsd, $size_sysv, $start_time,
$total_time, $username) ;

$hostname = "piglet";
$username = "blah";
$passwd = "blah1";
$filename = "topfile";



use Net::Telnet ();

$host = new Net::Telnet ( Timeout => 10,
Prompt => '/[\:$%#>] $/'),
$host->open($hostname);
$host->login($username, $passwd) ;

At this point the error message is:

"timed out waiting for command prompt at filename line 22 "

The code for the prompt should cover any prompt but I am using the "$" intentionally.

Any ideas?

Gerald
7 REPLIES 7
harry d brown jr
Honored Contributor

Re: perl Net::Telnet problem


Is this a TYPO??

$host = new Net::Telnet ( Timeout => 10,
Prompt => '/[\:$%#>] $/'),


because it should end in a ";"


live free or die
harry
Live Free or Die
Gerald Bush_2
Occasional Advisor

Re: perl Net::Telnet problem

It was not a typo. That was the example I used from the Net::Telnet cpan description. I added the " Prompt => '/[\:$%#>] $/'), "
from the perl cookbook from O'reilly.

I changed the "," to a ";" and I get the same timeout.

Gerald
Robin Wakefield
Honored Contributor

Re: perl Net::Telnet problem

Hi Gerald,

Looks like your prompt is the problem. The backslash should be the other side of the :, i.e.

Prompt => '/[:\$%#>] $/');

Rgds, Robin
Gerald Bush_2
Occasional Advisor

Re: perl Net::Telnet problem

Hi Robin,

Nice try but that isn't it. I actually added that to the prompt code I found in the Perl Cookbook.

I moved it and same error. I removed it and same error.

Thanks!
Gerald
Robin Wakefield
Honored Contributor
Solution

Re: perl Net::Telnet problem

Hi Gerald,

OK - if you telnet to piglet, what is the login prompt? Here's what works for me, first the telnet output, then the first part of the script - as you can see , the : at the login prompt matches, and I get the ls /tmp output with no problems:

ln4p2714-2 # telnet ln13p128
Trying...
Connected to ln13p128.
Escape character is '^]'.
Local flow control on
Telnet TERMINAL-SPEED option ON

login:



==========================================
#!/opt/perl5/bin/perl

my ($block, $filename, $host, $hostname, $k_per_sec, $line, $num_read,
$passwd, $prevblock, $prompt, $size_bsd, $size_sysv, $start_time,
$total_time, $username) ;

$hostname = "ln13p128";
$username = "wakefir";
$passwd = "mypasswd";
$filename = "topfile";



use Net::Telnet ();

$host = new Net::Telnet ( Timeout => 10,
Prompt => '/[:\$%#>] $/');
$host->open($hostname);
$host->login($username, $passwd) ;
print $host->cmd("ls /tmp"),"\n";
========================================

Rgds, Robin.
Gerald Bush_2
Occasional Advisor

Re: perl Net::Telnet problem

Robin, after looking at it again I used your code in another file. I changed host and bang it worked like a champ! Many thanks. My only problem now is figuring out why this one account won't work.

I have been beating my head against my desk on this since lunch yesterday. I am relatively new to perl and am simply trying to find perl solutions for my old scripts that used remsh and rcp as these are going away in our production environment. This answer just solved about 40% of my rewrites.

Gerald
H.Merijn Brand (procura
Honored Contributor

Re: perl Net::Telnet problem

1. Neither : nor $ should be escaped inside a character class inside a regular expression, so just drop the 2. If the login procedure waits for user input during the logon (like when asking for a terminal type in ttytype), the whole system times out

Use the "Dump_Log", "Input_log", and "Output_log" options (note the capital L in Dump_Log, I don't know why they used that inconsistently either) and check where the timeout happens (first browse the dump_log output.

Here is something I tried to get around the question:

use Net::Telnet;

my $host = Net::Telnet->new (
Timeout => 10,
Host => $hostname,
Dump_Log => "xx.dmp",
Input_log => "xx.inp",
Output_log => "xx.out",
Prompt => '/xterm..../'); # My tcsh asks for Term and shows xterm as default with 5 trailing backspaces
$host->login ($username, $passwd);
$host->prompt ('/\s>\s*$/');
$host->cmd ("dumb");
print $host->cmd ("ls /tmp"), "\n";
Enjoy, Have FUN! H.Merijn