in reply to SSH connection refusal kills CGI

I'm afraid that if you read the source, you'll see:

connect($sock, sockaddr_in($rport, $raddr)) or die "Can't connect to $ssh->{host}, port $rport: $!";

So the author has decided this is a fatal error. The traditional solution is to wrap the request in an eval to catch the exception:

eval { my $ssh = Net::SSH::Perl->new($tsip) } if ( $@ ) { # Error } else { # Success }

P.S. use strict; use warnings;


The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Replies are listed 'Best First'.
Re^2: SSH connection refusal kills CGI
by Dranzaz (Sexton) on Nov 25, 2005 at 15:53 UTC
    Thanks, that is what I needed. My updated version resembles:
    if ($@) { if ($@ =~ /Connection refused/) { print "<TD align=center bgcolor=#FF0000>Denied199</TD>"; $tssshtest = 2; } } else { if ($ssh = Net::SSH::Perl->new($tsip, protocol=>1)) { $ssh -> login ($username, $password); print "<TD align=center bgcolor=#00FF00>Granted</TD>"; $tssshtest = 1; } else { print "<TD align=center bgcolor=#FF0000>Denied</TD>"; $tssshtest = 0; } }

    All is better now. Many praises.