sierpinski has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Net::SSH::Expect timeout/delay issue
by salva (Canon) on Nov 14, 2009 at 12:04 UTC
      Thanks for the response. Unfortunately while I do follow the 'Yes even you can use CPAN' instructions, there are rules here against putting "production" code in place with non-company-approved modules, and the only SSH modules we are allowed are Net::SSH and Net::SSH::Expect. Also, even though it's not shown here I do utilize the Expect part of it as well.

      Our security team is strongly opposed to using anything with 'Open' in the title, regardless of it's security or functionality. Ah the corporate machine!

      Thanks!
      /\ Sierpinski
        Our security team is strongly opposed to using anything with 'Open' in the title, regardless of it's security or functionality. Ah the corporate machine!

        You are running Solaris on your servers, right?

        Try running there...

        $ strings /usr/bin/ssh |grep -i open