sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

Using the following code:

#!/usr/bin/perl -w use strict; use Net::Netrc; use Tie::File; use vars qw($CONF); $CONF = '/data/retprep/retlogs/retrieve.conf'; my @conf; tie @conf, 'Tie::File', $CONF or die("Unable to tie config file $CONF: + $!"); print "There are ". scalar(@conf), " records in config file $CONF\n"; foreach $_ (@conf) { chomp; my ($retid, $host, $files, $freq, $proto, $depricated, $prev_fdate +, $opts, $start_day) = split(/:/,$_,9); print "$host\n"; my $mach = Net::Netrc->lookup($host) || die $!; }

My script locks up with no error and I have to cntl-c to get back to my prompt.
My output is as follows:

There are 3 records in config file /data/retprep/retlogs/retrieve.conf ftp.some_domain.com/pub
If I comment out the Net::Netrc lookup then the script works fine. This of course is only a very trimmed down version of my actual script for automated ftp retrieval.

Prior to this I was not using Tie::File I was just openning the file and slurping it into an array. This too worked fine.

My system is an HP-UX 11 perl v5.6.1

If anyone has any suggestions I'd be eternally grateful.

TIA

Sweetblood

Replies are listed 'Best First'.
Re: Problem using Net::Netrc and Tie::File
by Zaxo (Archbishop) on Jun 12, 2004 at 05:08 UTC

    ~/.netrc is pretty much deprecated, and requires the most stringent permissions where it exists. I suspect your program lacks permission to read it. Your description of the problem doesn't sound like that, though. You check error in that call, and that ought to do the trick. Can you narrow down where your program stalls?

    After Compline,
    Zaxo

      Since the latest Net::Netrc is from 3/2004, and the Netrc and FTP man pages certainly don't mention that the use of ~/.netrc is deprecated. I don't believe it's use is deprecated.
      The file permissions for ~/.netrc are 0400 as specified in the documentation.
      Since the script hangs at the point it is accessing the netrc file I can do no further error checking. Also, since the script previously ran fine without the use of Tie::File I doubt that Net::Netrc is not setup correctly.
      This problem appears to be some buggy interaction between Tie::File and Net::Netrc
        I believe .netrc should be 0600 (read and write by owner), not 0400 (read only). At least it is so in my docs.

        Since the script hangs at the point it is accessing the netrc file I can do no further error checking.
        .. this might not be a correct assumption..

        Is that a far-reaching enough sample of your actual script -- the host lookup method by itself doesn't really "do" anything. However if you do (attempt) an actual ftp login you would get the hang/lockup if for any reason the ftp data connection cannot be built, for firewall rules or whatever reason.. just a thought. The default timeout is probably like 60 seconds.. a veritable eternity..