[Ssh-sftp-perl-users] [Fwd: Re: Trap connection errors somehow instead of just letting the whole sc
Brought to you by:
dbrobins
From: Nigel R. <ni...@sy...> - 2012-03-28 15:42:39
|
I didn't CC the list in my reply to Hans. This will be useful to others I'm sure. ---------------------------- Original Message ---------------------------- Subject: Re: [Ssh-sftp-perl-users] Trap connection errors somehow instead of just letting the whole script die. From: "Nigel Reed" <ni...@sy...> Date: Wed, March 28, 2012 10:14 am To: "Hans de Groot" <ha...@da...> -------------------------------------------------------------------------- Hans de Groot wrote: > But some times during a session (lots of data) the script dies with: > > Connection failed: Connection reset by peer > at /usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm line 568 > > But I need the script to keep running and detect these errors and try to > reconnect and resume copyinf file. But it seems it's out of my hands? I do something like this. eval { $ssh = Net::SSH::Perl->new($host, ( protocol => 2, debug=>$debug )); }; if ($@) { print "EREOR! Cannot connect to $host $@\n"; noconnect($host); $pm->finish; next; } else { print "CONNECT $host\n"; } Basically, wrap your command in an eval, then use $@ to determine if there was a connection. -- Nigel Reed -- Nigel Reed |