<sigh> I found that wrapping the "new" method with an "eval {}" does
the trick, also wrapping the login in a second eval catches other
possible errors. This works for my purpose of simply dropping to telnet
for that host.
I learned me something new. :)
Nick
PS: My code sample
sub get_config_ssh{
$hostname = @_[0];
print "Connecting SSH to: $hostname... ";
use Net::SSH::Perl;
eval {
$ssh = Net::SSH::Perl->new("$hostname");
};
if($@) {
print "\n\n\nHOLD THE PHONE, SSHD not available!!\n\n\n";
}
$ssh->login("me",pass");
($out, $err, $exit) = $ssh->cmd("show ver");
print "out:\n $out\n\nerr:\n$err\n\nexit:\n\$exit\n\n";
}
Nick Ellson
Infrastructure Specialist
PGE, Network Operations Center
Personal: (503) 464-2995
Network Trouble: (503) 464-8754
"Educating Layer 8, one user at a time."
>>> "Nick Ellson" <Nic...@pg...> 08/09/2006 7:28 AM >>>
I have a net--telnet script that collects data from Cisco devices, and
it's pretty basic. I am adding ssh v1 &v2 support so I can collect
data
from devices that force Cisco's SSH version on that device. So far, as
long as the device answers to ssh, it was a pretty easy task. But if
the
system has no ssh ability, and I hit it with the script, it dies and
kills my script.
I have not done much error handling with scripts, so I was hoping I
could get some ideas on how to allow my script to recover from this
connection failure and let me drop to a telnet attempt.
I suppose I could do a test before calling the ssh module, see if
tcp/22 is answering, but net::telnet does a nice job of providing an
error of it cannot connect, does net::ssh::perl do that?
Nick
Nick Ellson
Infrastructure Specialist
PGE, Network Operations Center
Personal: (503) 464-2995
Network Trouble: (503) 464-8754
"Educating Layer 8, one user at a time."
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Ssh-sftp-perl-users mailing list
Ssh...@li...
https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users
|