Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi ALL

I am facing a problem with the NET::TELNET module. I am telnetting to a linux box and there I am trying to run perl script which actually is a expect script. So now the problem is that when the perl expect script is running remotely I am supposed to execute a command and wait for its completion and then execute the next command when I get the prompt. The problem is that I am not able to get the complete command execution and hence the next prompt. I wonder what the problem is, is it like the telnet window is smaller or the output buffer allocated to the telnet session through the perl module is small. Can anyone explain. I have copied some part of the code I hope it helps you.

windows pc telnet code

$telnet_box->open("$host") || die "Failed to connect to $host $!"; $telnet_box->login($user_name, $password) || die "Failed to log onto $host. The username or password is wro +ng$!"; @$lines = $telnet_box->cmd("perl expect_execute.pl");
Linux box expect script code:
$exp_inst->log_file("$templog", "w"); $exp_inst->expect($timeout, [ '-re' , $prompt, sub { my $fh = shift; $fh->send("$command\n"); } ], [ timeout => sub { my_die "unable to get the prompt $prompt"; } ] );
Output :
prompt> command More ...
Expected:
prompt> command xyz yy prompt>
Thanks in advance

Replies are listed 'Best First'.
Re: net::telnet problem
by graff (Chancellor) on Jun 25, 2005 at 22:49 UTC
    It's not clear what you're trying to do, and I'm wondering if your approach is more complicated than it needs to be. It sounds like:
    • A perl script on a windows box uses Net::Telnet to start up ...
    • A shell on a linux box that uses Expect to start up ...
    • An interactive program of some sort on the linux box that presents a command line prompt where you need to ...
    • Pass a sequence of commands to this other (non-Perl?) interactive program.
    And then what? Does the third(?) program produce some output that you want to capture on the windows box?

    If that's roughly what your trying to do, Net::Telnet supports some amount of "Expect"-like behavior, so maybe you could leave out the second perl script, and run the command line program directly from the windows process, without the middle-man perl script running on the linux box. (Having two "Expect"-like scripts chained together this way seems unnecessary, and prone to all sorts of problems with deadlock.)

    If I guessed wrong about what you're doing, you need to give more detail.