If I understand your question, the response you are looking for is in the prematch of the last OK.

Something like this:

#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11155061 use warnings; use Net::Telnet (); my $host='192.168.1.13'; # FIXME my $t; my $oid; {$t = new Net::Telnet (Timeout => 10,Input_log => "received_data.txt" +, Port => 12345, # FIXME Prompt => '/bash\$ $/'); $t->open($host); $t->print("AT"); #this is just used to make sure it connects## $t->waitfor('/AT/'); #this is just an echo back of what is sent## $t->waitfor('/OK/i'); #send this to say I'm ready## } {$t->print("AT%23=1234"); #This basically the password to the system# +# $t->waitfor('/AT%23=1234/i'); #Echo back## $t->waitfor('/OK/i'); } { $oid = $t->print("AT1122"); #This is the command to see the state## $oid = $t->waitfor('/AT1122/i'); #Echo back## #$oid = $t->waitfor('//'); #this could be 0,1,2...need to converto oi +d### # #Need this value to check state in SNMP## my ($returnedvalue, $match) = $t->waitfor('/OK/i'); $returnedvalue =~ tr/0-9//cd; # delete everything except digits print "this is what I think you are looking for: $returnedvalue\n"; } $t->close()

Outputs:

this is what I think you are looking for: 2

Note: a few tweaks were made to run it on my machine...


In reply to Re: Telnet responses by tybalt89
in thread Telnet responses by mikebailey

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.