Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Problem retrieving data using WWW::Curl

by gizmo2 (Initiate)
on Jun 13, 2005 at 12:28 UTC ( [id://466131]=perlquestion: print w/replies, xml ) Need Help??

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

hello,
i'm a newby and not very good at cgi/perl and i'v been trying for 2 day's now to get this script i found on the internet to work

this is the page of the scripts article: http://www.devarticles.com/index.php?option=content&task=view&id=622

I only need the part where it get's the info files form the servers and then updates the database to work!
which is this part but cant get it to work:
#!/usr/bin/perl my ($ip_date, $file_time, $file, $apnic, $ripe, $arin, $lacnic, @regis +tries, $url, $curl); $ip_date = (strftime("%Y%m", localtime(time)))."01"; $file_time = (strftime("%Y%m%d-%H%M", localtime(time))); $file = $file_time."_ip_data.txt"; $apnic = "ftp://ftp.apnic.net/pub/stats/apnic/apnic-latest"; $ripe = "ftp://ftp.apnic.net/pub/stats/ripe-ncc/_ripencc.latest"; $arin = "ftp://ftp.apnic.net/pub/stats/arin/arin.".$ip_date; $lacnic = "ftp://lacnic.net/pub/stats/lacnic/lacnic.".$ip_date; open (BODY,">>$file"); @registries=($apnic,$ripe,$arin,$lacnic); foreach $url(@registries) { # Init the curl session $curl= WWW::Curl::easy->new() or die "curl init failed!\n"; $curl->setopt(CURLOPT_URL, $url); $curl->setopt(CURLOPT_FTP_USE_EPSV, '0'); $curl->setopt(CURLOPT_FILE, *BODY); if ($curl->perform() != 0) { print "Failed ::".$curl->errbuf."\n"; } } close BODY; $dbh = DBI->connect("DBI:mysql:host=localhost;database="data_base","us +er","pass",{PrintError=>0,RaiseError=>1}); $sth = $dbh->do("DELETE from ip_map"); print "\n\nData from ip_map table dropped\n\n"; $sth = $dbh->prepare("INSERT into ip_map values (?,?,?,?)"); $count = 0; open (PROCESS, "<$file"); while ($line = <PROCESS>) { chomp ($line); if (($line =~ m/\|ipv4\|/) and ($line !~ m/\*/)) { ($registrar,$country_code,$item_type,$start_ip,$num_ip,$entry_date, $r +egistry_type) = split(/\|/, $line); @octets_start = split(/\./, $start_ip); $long_start = 0; foreach $octet_start (@octets_start) { $long_start <<= 8; $long_start |= $octet_start; } $long_end = $long_start + ($num_ip-1); $count += $sth->execute($country_code,$registrar,$long_start,$long_end +); } } close PROCESS;
if i upload this script as a .cgi or .pl with chmod 755 and then call it in the browser nothing happens, no error's either. am i missing a path to files or something? do need to call this form shell? curl is installed!

can some one please help me with this!!!!

thanx for your help

Janitored by holli - added code tags

Retitled by holli from 'PLEASE HELP'.

Replies are listed 'Best First'.
Re: Problem retrieving data using WWW::Curl
by robartes (Priest) on Jun 13, 2005 at 12:46 UTC

    Given that in your script, you use:

    $curl= WWW::Curl::easy->new() or die "curl init failed!\n";

    and that you do not use WWW::Curl::easy, chances are that your script bombed out at that line. Check your web server's error log to see the messages from the script.

    Also, if this is supposed to be a CGI script, perhaps you should consider outputting valid HTML -- CGI is a good place to start with this.

    CU
    Robartes-

      have run it form command line! firts gave error about

      $ip_date = (strftime("%Y%m", localtime(time)))."01";


      Undefined subroutine &main::strftime called at geo_db.pl line 2.

      commented this part out then it came accross your remark
      $curl= WWW::Curl::easy->new()

      Can't locate object method "new" via package "WWW::Curl::easy" (perhaps you forgot to load "WWW::Curl::easy"?) at geo_db.pl line 14.

      changed itas you recommened but now it still gives this error:

      Can't locate object method "setopt" via package "WWW::Curl::easy" (perhaps you forgot to load "WWW::Curl::easy"?) at geo_db.pl line 15.

      don't realy understand what it means by this? thanx for the feedback!
        Undefined subroutine &main::strftime called at geo_db.pl line 2.
        Can't locate object method "new" via package "WWW::Curl::easy" (perhaps you forgot to load "WWW::Curl::easy"?) at geo_db.pl line 14.

        Both these errors are consequences of the same basic fact: you are using functions from modules that are not loaded. Before you use functions from a module, you need to explain perl that you will be using these modules. Perl being what it is, that means you just need to tell it so:

        #!/usr/bin/perl -w use Posix; # strftime() lives here use WWW::Curl::easy; # WWW::Curl::easy::new() lives here

        Judging from these questions, you might benefit from reading a good book on learning Perl. Again, Perl being what it is, there is actually a good book called Learning Perl, which I can recommend heartily.

        CU
        Robartes-

Re: Problem retrieving data using WWW::Curl
by Joost (Canon) on Jun 13, 2005 at 12:49 UTC
      hi if it's not a cgi script do i need to give it .cgi extention at all? and how shoud i call this? with what function? or does it just run?
        You call it as every perl script.
        bash> perl yourscriptfile
        Or, if the the script includes a shebang-line (#!/usr/bin/perl), make it executable via chmod and
        bash> yourscriptfile
        The extension is normally just important for the webserver, and even that is a configuration issue.

        On windows the extension is more important, because there the shebang line has no influence on which perl is used. There normally the extension ".pl" is associated with perl.
        C:\> yourscript.pl
        However, the first way with explicitly calling the perl interpreter works on both systems.


        holli, /regexed monk/
Re: Problem retrieving data using WWW::Curl
by davidrw (Prior) on Jun 13, 2005 at 12:43 UTC
    What is the directory you're uploading to (and you're _sure_ the permissions are correct? What is the url you're using? What's the exact browser error (i.e. what does "nothing happens" mean)?

    Also, be sure to take a look at How (Not) To Ask A Question and also at Writeup Formatting Tips for how to use code and readmore tags to make it easier for everyone to see/read/understand (read: be willing to respond to) your post.
      this is the link of the script on my server http://www.nudaten.nl/cgi-bin/geo/geo_db.pl

      just gives a page not found 500 error the geo dir is chmod 777
        Don't put CGI scripts in a directory chmoded to 777, it's a Bad Idea TM. It means that ANYONE can write to that directory. Is that really what you want? 755 is a much safer idea :)

        ----------
        My cow-orkers were talking in punctuation the other day. What disturbed me most was that I understood it.

Re: Problem retrieving data using WWW::Curl
by thcsoft (Monk) on Jun 13, 2005 at 12:29 UTC
    what about a readable version?

    language is a virus from outer space.
      yes wel wasn't expecting to have to add all
      my self :) fixed it now
        next time, wrap your code inside <code>...</code> tags!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://466131]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found