Hi Monks,

Hopefully someone out there can tell me what is going on with my Telnet code. First here is the code

my $prompt = "someprompt"; my $t = new Net::Telnet (Errmode => "return", Prompt => '/\$ $/i'); my $ok = $t->open("10.1.46.16"); Error() if $ok != 1; # print "open $ok\n"; $ok = $t->login($username, $passwd); Error() if $ok != 1; # print "login $ok\n"; $ok = $t->print("PS1=$prompt"); Error() if $ok != 1; # print "set prompt $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for set prompt $ok\n"; $ok = $t->print('CT'); Error() if $ok != 1; # print "CT $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for CT $ok\n"; $ok = $t->print("$cmd"); Error() if $ok != 1; # print "run_ct $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for run_ct $ok\n"; $ok = $t->print("ps -ef | grep run_ct | grep -v grep"); Error() if $ok != 1; # print "ps -ef $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for ps -ef $ok\n"; my $ps = $t->get(); print "get = $ps\n"; my $process_id = (split /\s+/,$ps)[2]; print "\$process_id = $process_id\n"; $t->close; # Check if process has finished INF: for(;;) { print "loop\n"; my $t = new Net::Telnet (Errmode => "return", Prompt => '/\$ $/i'); my $ok = $t->open("10.1.46.16"); Error() if $ok != 1; print "open $ok\n"; $ok = $t->login($username, $passwd); Error() if $ok != 1; print "login $ok\n"; $ok = $t->print("PS1=$prompt"); Error() if $ok != 1; print "prompt $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; print "wait for prompt $ok\n"; $ok = $t->print("ps -ef | grep run_ct | grep -v grep"); Error() if $ok != 1; print "ps -ef $ok\n"; $ok = $t->waitfor("/$prompt/"); # Error() if $ok != 1; print "\$ok = $ok\n"; print "wait for ps -ef $ok\n"; $ps = $t->get(); print "get = $ps\n"; my $process_id2 = (split /\s+/,$ps)[2]; print "process_id = $process_id\nprocess_id2 = $process_id2\n"; unless(defined $process_id2 && $process_id == $process_id2) { $ok = $t->print("CT"); Error() if $ok != 1; # print "CT $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for CT $ok\n"; $ok = $t->print("cat $logfile"); Error() if $ok != 1; # print "cat $ok\n"; $ok = $t->waitfor("/$prompt/"); Error() if $ok != 1; # print "wait for cat $ok\n"; my $log_contents = $t->get(); print "$log_contents\n"; last INF; } $t->close; sleep 10; }

Now when i perform the first 'get()' i get the output from my 'ps' command. Now here is the strange thing.....when i do the second 'get()' i get my 'ps' command echoed in the output which then stuffs up my split. Why am i getting two different answers from exactly the same code. Any thoughts would be most welcome as this is driving me crazy!

TeraMarv.


In reply to Strange behaviour - Net::Telnet by TeraMarv

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.