On Mon, Mar 24, 2008 at 2:25 PM, Wagner, David --- Senior Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote: > I have a polling process that runs 24x7 ( internal site ) and for the > most part has no problems except that they shutdown the the internal > site every three or four weeks and my process then dies. > > I have a simple setup: > > $MyFtp = Net::FTP->new($GlblInfo{ipaddr}, Debug => 1); > > $MyFtp->login($GlblInfo{logon},$GlblInfo{pw}); > > Yes. There is no checking on the new and what happens is that > new fails and then when it tries the login, I get a failure for the > method login. So how do I surround the new so that if it fails, I can > go to sleep for say five minutes and then try again until I hit some > limit or timeframe? snip
Throw the login into an eval {} to prevent the die from killing the script and use a loop for max tries: use constant MAX_TRIES => 3; use constant WAIT_BEFORE_RETRY => 60*5; my $try = 1; until (eval { $MyFtp->login($GlblInfo{logon},$GlblInfo{pw}; 1}) { die "login to $GlblInfo{ipaddr} as $GlblInfo{logon} failed (try $try): $@"; if ++$try == MAX_TRIES; warn "login to $GlblInfo{ipaddr} as $GlblInfo{logon} failed (try $try): $@"; sleep WAIT_BEFORE_RETRY; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/