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

Im simply looking to check if an attempt to ssh to a host is successful, and nothing more. I have achieved this by the following :
close(STDERR) # ie I Dont want to see junk if ( &Net::SSH::ssh('user_that_fails@somehost', "exit") ) { print "A message - you just failed \n"; } else { print "A message - you just passed \n"; }
This seems to me to be the wrong way around, ie returns true when using a username that fails. More importantly, is there a better way of doing this ? ( sorry but I cant use Net::SSH::Perl ) NB - Not shown, but STDERR is saved off to a temp handle, and restored afterwards. Thanks.

Considered by jdporter: reap: dupe of Connection test : Net::SSH::Perl : $ssh->login - detecting failure
Unconsidered by Arunbear: keep (and edit) votes prevented reaping; Keep: 3, Edit: 1, Reap: 17

  • Comment on (DUPE) Is there a better way ? : Net::SSH - Detecting success or fail for a connection
  • Download Code

Replies are listed 'Best First'.
Re: Is there a better way ? : Net::SSH - Detecting success or fail for a connection
by u235sentinel (Hermit) on Feb 18, 2006 at 02:20 UTC