in reply to Net::SSH question

The most obvious problem I see is that you talk of using Net::SSH but then refer to Net::SSH::Perl. Those are two different packages.

Have you considered placing your ssh connection inside an eval block?

No good deed goes unpunished. -- (attributed to) Oscar Wilde

Replies are listed 'Best First'.
Re^2: Net::SSH question
by ptum (Priest) on Nov 24, 2005 at 00:52 UTC
    Sigh. Too bad I don't read the manual. I tried putting a simple ssh connection inside eval and discovered it didn't trap STDERR, as it says in http://www.perl.com/doc/manual/html/pod/perlfunc/eval.html. Sorry for the bad advice.

    "Beware that using eval() neither silences perl from printing warnings to STDERR, nor does it stuff the text of warning messages into $@. To do either of those, you have to use the $SIG{__WARN__} facility. See warn and the perlvar manpage."

    No good deed goes unpunished. -- (attributed to) Oscar Wilde
      ptum:

      You are right, it's Net::SSH::Perl I'm using, but I had lost my browser window by the time I had figured it out, and don't know how to edit the original post until there have been replies to it.

      Anyways, I can probably avoid this problem if I can figure out how to use the other authentication methods. AFAIK, it's using rhosts... the server in question though, has IgnoreRhosts set to "yes", so that won't work. Nobody will have access to this script, so I really just want to do password authentication, but can't find in the docs (or any other pages) on how to sort that out.

      Thanks for the effort thusfar. EDIT: No, it's not reading rhosts. O_o I guess I need to fix the sshd_config file on the server then.
        OK, this will not work for Net::SSH::Perl -- I don't have that module installed, and I hear it is nontrivial on a Solaris platform. Besides, at some point I need to go home. But your problem intrigued me because I currently had no way to handle problems with my existing Net::SSH use. I played for quite a while with IO::Capture before I realized that the output from the Net::SSH->ssh() method was neither STDERR nor STDOUT for my script.

        So I wrote a little program using Net::SSH->sshopen3() which seems to work pretty well in both the happy and unhappy cases:
        #!/usr/local/bin/perl -w use Net::SSH qw(sshopen3); use strict; Main: { my $host = 'nobody@nowhere.com'; my @command = ('ls -al;', 'echo Howdy!'); my $reader = IO::File->new(); my $writer = IO::File->new(); my $error = IO::File->new(); sshopen3( $host, $writer, $reader, $error, @command ) or die $!; local $/ = undef; my $output_stream = <$reader>; my $error_stream = <$error>; if ( length $error_stream ) { print "SSH error: $error_stream"; } if ( length $output_stream ) { print "SSH output: $output_stream"; } }
        If you use the $host string I have provided, you should see a message to that effect in $error_stream, which you could capture and reformat for display in your CGI script. I hope that helps you at least a little.

        No good deed goes unpunished. -- (attributed to) Oscar Wilde