in reply to how to handle login failures with Net:::SSH::Perl?

Can't you just grab the returned exit value?
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

Replies are listed 'Best First'.
Re^2: how to handle login failures with Net:::SSH::Perl?
by jfroebe (Parson) on Sep 21, 2004 at 13:25 UTC

    Unfortunately, no. Ends up being we need to place the $ssh->cmd() within an eval block. Net::SSH::Perl was designed to die() if the connection attempt fails.

    I was hoping to avoid an eval block as I really don't like them because they require a recompilation each time we encounter an eval block. As the camel book says, it is a performance hit.

    eval { ($stdout, $stderr, $exit) = $ssh->cmd("df -k $dump_dir"); }; if ($@) { print "SSH Connection attempt failed\n" if ($@ =~ m/Permission denied/i); }

    The login() method doesn't do anything but set the settings for the connection.. It doesn't actually connect to anything.

    Jason L. Froebe

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      ...they require a recompilation each time we encounter an eval block...it is a performance hit.
      There is no "performance hit" from the eval in your code (at least not nearly as much as you think there is). eval $string has a performance hit, as perl does have to compile the code in $string each time, but not in eval { BLOCK }, because the code in the BLOCK is already compiled. See the eval docs in perlfunc.

        insert a Home Simpson DOH! ;-)

        Jason L. Froebe

        No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      I think you're going to see an even more significant performance hit from running ssh and df -k over and over before you notice a performance penalty from eval :-)