Solved

Hung process,  Net::Ftp

Posted on 2000-03-02
2
210 Views
Last Modified: 2008-03-17
I have a robot which is run, via cron, every 15 minutes.  It uses Net::Ftp to connect and download some file from a Ftp server...  The problem is that this service is not 100% reliable.  Sometimes I can't connect, but this is handeled by the Timeout option which I have explicilty set to 20 (Timeout => 20) but this only applies to a connection.  Once I have a valied connection it no longer applies and thats when my problems start...

Sometimes I my be logged in, do an ls and never get a response yet the connection is still alive.  When this happens the whole script hangs.  The real problem is that after about 3-4 days Cron has so many quequed processes that it begins to ingnore or kill off jobs at random and at that point I'm %^%$^%$^%.  Any ideas...?  Something clean.  I already have a shell script that goes in and kills the hung processes but that is dirty and ugly and not the solution.
0
Comment
Question by:guadalupe
2 Comments
 
LVL 3

Accepted Solution

by:
jyu_88 earned 100 total points
ID: 2584192
you can do a timeout in your script taking advantage of an 'alarm' function. 'alarm $timeout' will deliver an ALRM signal to your PERL  process after $timeout seconds , then your own handler can quit out the perl script gracefully. The example in 'perlfunc' manpage is easy enough to follow.                  
eval {
     local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
     alarm $timeout;
     $nread = sysread SOCKET, $buffer, $size;
     alarm 0;
};
if ($@) {
      die unless $@ eq "alarm\n";  
      # propagate unexpected errors
      # timed out
}
else {
     # didn't
}

If you have some means with the remote FTP server admin, you can request them to set 'stalk timeout'. The latter is avaiable for some FTP servers, such as proFTPd.
0
 
LVL 3

Author Comment

by:guadalupe
ID: 2612684
Thanks that did the trick!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
use perl to insert into MySQL database 9 128
hard perl script 16 154
Migrate OTRS to newest version. 1 312
Perl Frameworks 1 81
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now