Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
When I use Net::Telnet my command works but it also echoes the command and I want just the results. The docs for Net::Telnet talk about this and suggest using cmd_remove_mode, yet I still get the same result in my output. I've been working on this silly problem for hours. It seems so simple but I cannot figure out what I'm missing here?

Here's my code:

#!/usr/bin/perl use strict; use warnings; use Net::Telnet (); my $t = new Net::Telnet (Timeout => 10, Prompt => '/host\@user ~\/'); my ($username, $passwd) = qw(user password); $t->open("host"); $t->login($username, $passwd); my @distro = $t->cmd(String => "cat /etc/redhat-release", cmd_remove_mode => '1'); print "@distro";
Which produces this output:
$ ./connect.pl $ cat /etc/redhat-release CentOS release 5 (Final)

and I don't want the cat command. Can anyone shed some light?

UPDATE:
Set cmd_remove_mode to the number of lines to remove such as

my @distro = $t->cmd(String => "cat /etc/redhat-release", cmd_remove_mode => '2');

to remove two lines.

In reply to Can't get cmd_remove_mode to work in Net::Telnet by gctaylor1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Corion]: erix: Yes, but that's mostly for skipping characters you'll never read, but this approach skips the problem of needing to load more data while looking at a half-match
    [Corion]: I mostly wonder how I can add this "reversal" to my toolchest, and if it's worth it or just clever
    [choroba]: It should greatly simplify the parsing code, no flags or additional reading of the next buffer needed
    [Corion]: choroba: Yeah, that's why I like that approach; it seems even quite obvious in retrospect to me, but many things are in hindsight ;)

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (13)
    As of 2016-12-06 15:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      On a regular basis, I'm most likely to spy upon:













      Results (109 votes). Check out past polls.