Of course! (head slap) :)

I was already gathering the info, but didn't think of using it to automatically pull the error:

my $ssh_debug = 0; # verbose logging: 0-3 ... my $session_log_name = "ssh_$host.log"; open( my $session_log_fh, ">", $session_log_name ) or die "Failed to create logfile $session_log_name: $!"; binmode( $session_log_fh, ":unix" ); # unbuffer log file ... $ssh_session{$host} = Net::OpenSSH->new( # host $host, # automatically add new host keys to the user known hosts file +s # enable verbosity, if enabled master_opts => ($ssh_debug) ? [ -o => "StrictHostKeyChecking=no", "-" . "v" x $ssh_debug ] : [ -o => "StrictHostKeyChecking=no" ], # authentication user => $username, password => $password, # logging master_stderr_fh => $session_log_fh, # connection parameters timeout => $loginTO, port => $ssh_port, async => 1 ); }

The '-v' to enable debugging is not required in this case, as the error message (or nothing) will be written to the file with $ssh_debug = 0. I believe the important concept here is the cause of error message always appears to be the last line output to the master_stderr_fh file. Something like the following (combined with the above) appears to provide a more accurate error message:

elsif ( $ssh->error ) { # handle connection error my $lasterr = File::ReadBackwards->new("ssh_$host.log")->r +eadline; # ... something that outputs or logs the error message }

It should be noted there will be a linefeed on the end of $lasterr (it's left up to the user to chomp it off if they don't want it).

It should also be noted that master_stderr_fh cannot be assigned to an in-memory file, or the following error will be received:

Not a GLOB reference at /usr/local/share/perl/5.14.2/Net/OpenSSH.pm li +ne 614. 612 sub _check_is_system_fh { 613 my ($name, $fh) = @_; 614 my $fn = fileno(defined $fh ? $fh : $name); 615 defined $fn and $fn >= 0 and return; 616 croak "child process $name is not a real system file handle"; 617 }

Thanks again. The full solution will be posted when it is done (I'm juggling a couple of other things while doing this, so sorry it's taking a while).


In reply to Re^8: SSH2 - Asynchronous Opens & Synchronous Commands by 5haun
in thread SSH2 - Asynchronous Opens & Synchronous Commands by 5haun

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.