Hello again monks,

I've asked a couple previous questions about this monstrous monitoring script I'm working on. Currently I'm having an issue where once my expect object processes some output, there is some leftover in STDIN that carries over to the next check. This is causing some unexpected results. Here is a chunk of code:

$ssh->send("$svmmaint_cmd"); my $line; my $svm_error=0; while ( defined ($line = $ssh->read_line()) ) { if($line =~ /err|maint|repl|sync/i) { $svm_error = 1; } } if($svm_error) { open(SVM,">>$SVMMAINTFILE"); print SVM "$serverlist[$host] has a bad mirror/disk\n" +; close(SVM); $svm_error=0; $ssh->read_all(2); # Tried to flush the input buffer +here, no dice } # Flush the input buffer $ssh->read_all(1); # sometimes this works on other checks, bu +t doesn't help here either $line = ""; # this was no help either # This is a new check, same ssh connection/expect object # Execute metadb check $ssh->send("$metadb_cmd"); my $line; while ( defined ( $line = $ssh->read_line()) ) { print("$serverlist[$host] - $line\n"); if($line < 6) { open(MDB,">>$METADBFILE"); print MDB "$serverlist[$host] has less than 6 +metadbs\n"; close(MDB); } }

So I have a print statement in the 2nd check that should print '6' if it's set up correctly. This tells us that we have 3 metadbs on 1 disk, and 3 on another, so if we lose 1 disk we still have a good set of useful information. Any less than that and we're at risk for having a server not be bootable.

The problem is that the first check (checking to see if there are errors on the disk) has output that looks like this:

server1 - 6 server2 - 6 server3 - 9 server4 - 9 server5 - State: Needs maintenance server5 - State: Needs maintenance server5 - Invoke: metareplace d105 c4t1d0s4 <new device> server5 - c4t1d0s4 0 No Maintenance Yes server5 - 6 server6 - 6 server7 - 6
So the first check listed above checks for the "needs maintenance" state of the 'metastat' command. The second check just counts the lines in a 'metadb' output.

Some things I've tried:

Looking for the prompt to signal the end of output. Problem with this is not all prompts are similar, and I have no control over that.

Using exorbent timeouts with read_all: Even waiting for as long as 10 seconds hasn't made a difference, I still get the above output.

If anyone has any thoughts about how I can properly (and consistently) segregate my various command inputs and output from each other, it would greatly help me out.

Thanks as always!

/\ Sierpinski

In reply to Net::SSH::Expect timeout/delay issue by sierpinski

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.