Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

maximum result size for Net::Telnet's cmd() method

by dsb (Chaplain)
on Jun 12, 2006 at 13:05 UTC ( #554799=perlquestion: print w/replies, xml ) Need Help??

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

Does anyone know if there is a maximum result size for Net::Telnet's cmd() method? The docs don't mention anything.

The situation is, I'm returning a result set into an array, and the result set it being truncated.

my @ps = $t->cmd( "ps -elf" );
So @ps should have say 70 lines, instead it has only 60. When I run this command from the command line on the target box, the results are as expected. The line I'm looking for is towards the end of the result set, so if I modify the ps command with a grep pattern, I do wind up seeing the line I'm looking for. This tells me that what is being returned by cmd() is not what it received from the other box.

This @ISA my( $cool ) %SIG

2006-06-12 Retitled by Corion, as per Monastery guidelines
Original title: 'Net::Telnet'

Replies are listed 'Best First'.
Re: maximum result size for Net::Telnet's cmd() method
by jasonk (Parson) on Jun 12, 2006 at 13:32 UTC

    I haven't seen any result size issues (and I've used it to run some commands with huge amounts of output), most of the time when I've run into problems with the result data being truncated, it has been due to my prompt() regexp being a little too simplistic, and it is matching something in the output. Be especially careful of prompts that contain dollar signs, $tn->prompt("foo$ ") will match anything that contains 'foo'...

    What I usually end up doing when I need to parse output that may contain data that looks like the prompt, is to do something like this instead of using cmd:

    my $tn = Net::Telnet->new(); # setup your connection here... my $tag = "___END_OF_COMMAND___".time()."_".$$; $tn->print("some command goes here ; echo $tag"); my($pre,$match) = $tn->waitfor( String => $tag ); my @output = split(/\r?\n/,$match);

    Another option is to adjust the prompt on the remote server to be something you can readily identify that isn't likely to appear in your command output...

    my $prompt = "___NET_TELNET_PROMPT_DETECTOR___".time(); $tn->cmd("export PS1=$prompt"); $tn->prompt("$prompt");

    We're not surrounded, we're in a target-rich environment!
Re: maximum result size for Net::Telnet's cmd() method
by odha57 (Monk) on Jun 12, 2006 at 13:27 UTC
    I have run into the same thing trying to gather up a couple hundred lines. I ended up getting it to work using print and waitfor. Using your example it would look like this:
    $t->print("ps -elf"); @ps = $t->waitfor('/your_stuff/');
    with 'your_stuff' being what you are looking for in the command. I found this in the the Network Programming with Perl book by Lincoln Stein. A quite handy book by the way. Hope this helps.

      Which, if you actually read the source is exactly what cmd() does:

      ## Send command and wait for the prompt. $self->put($cmd . $ors) and ($lines, $last_prompt) = $self->waitfor($prompt);

      So no, there is no direct limit on the number of lines returned, only the indirect limit placed by the timeout.

      The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: maximum result size for Net::Telnet's cmd() method
by ptum (Priest) on Jun 12, 2006 at 13:11 UTC

    You might consider using the dump_log method and adjusting the timeout parameter ... that might help you or at least help to identify the problem.

    No good deed goes unpunished. -- (attributed to) Oscar Wilde

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://554799]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-11-27 21:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found