I am trying to run a who command on a remote server using Net::Telnet


1. use Net::Telnet; 2. $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die',Input_Log= +>'out.txt',Prompt=>'/.*tstbld.*/'); 3. $telnet->open('seahawk'); 4. $telnet->login('tstbld', 'vilc0n'); 5. $telnet->cmd(String=>'cd /builds/htpc2003r1/base/menu', Prompt=>'/. +*htpc.*/'); 6. $prompt = '/pkmsqa/'; 7. print $telnet->cmd(String=>'who', Prompt=>$prompt);


When I see the actual output from line 7 in out.txt file, it shows all lines returned by who command. Basically the command prompt is returned twice, once before the results and once after the results

[/builds/htpc2003r1/base/menu] seahawk:>who pkmsqa pts/0 Nov 07 03:19 (10.80.12.176) tstbld pts/3 Nov 07 08:40 (10.80.12.176) tstbld pts/4 Nov 08 02:35 (10.80.12.154) pkmsqa pts/5 Nov 08 04:59 (10.80.12.154) [/builds/htpc2003r1/base/menu] seahawk:>

In line 6 if I specify prompt = ‘/pkmsqa/', it returns everything before pkmsqa
[/builds/htpc2003r1/base/menu] seahawk:>who

If I specify prompt = ‘/>/', it returns everything before the first occurrence of >

[/builds/htpc2003r1/base/menu] seahawk:

How do I specify prompt so that it returns me everything before the second > I tried /Z option, $& option, >& option but nothing works. The match is always being done with first occurrence and not the last occurrence.

Thanks, KK


In reply to Matching prompt in Net::Telnet by kkarne

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, details, 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, summary, 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.