Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help writing a Perl script

    Hi, I need help writing a perl script that will be run as a cron job. I need the script to connect to a webserver and download a specific page (just the source, no pictures or anything), and then save that to my server. I tried a script already (attached) but it says unknown error on line 25 when I tried using it (in Windows with ActivePerl). If anyone could help me out, that would be great. Thanks!
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    obviously (hopefully) you are running your own webserver.

    all you have to do is go to CONTROL PANEL > SCHEDUALED TASKS (im 14 so dont ask me how to spell schedualed). and then add a schedualed task to be executed at the time you want. for exacmple, you want your script (probabily url.pl) to be executed every hour on the hour.

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    H-Town
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What does being 14 have to do with knowing how to spell? Just curious...

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    who knows ... i had to find some excuse for misselling it.

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My perl script that I attached doesn't work though, I need help writing a new one or somehow fix the one I have. To me there doesn't seem like there is anything wrong with it. The script looks like it'll print the source of the website to the screen, and it shouldn't be hard to have it write to a file instead. It'll be running as a cron job on a Novell server that runs Apache as the webserver.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't bother with using the low-level Socket module - it's more hassle than it's worth, try taking a look at this example webget client, it's what you're after I think.
    You'll have to hack about with it a bit of course, but I always use this as a base when I'm playing with sockets, for some reason I can never remember how to use them off the top of my head...

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, after actually looking at your code I thought I'd just post a couple of points...
    1)# #!/usr/local/bin/perl -w
    Why have you commented out the shebang line....?
    Just leave it as #!/usr/local/bin/perl -w and even if it's on a windows system where the path isn't important it'll give you warnings like you want.

    2)die "Usage $0 host page \n" if $#ARGV <1;
    Ok, this looks exactly like you've tried to hack around with a webget client... however you don't want to be doing things like this in a CGI context. Arguments aren't passed to CGI scripts in the same way that they are on the command line. This script will always die with this line in because the script will (probably) never have any arguments passed to it through the @ARGV array.

    If you want this to work as a CGI script then you'd have to do something like this:

    Code:
    #!/usr/local/bin/perl -w
    use CGI qw(:standard);
    $host = param('host');
    $page = param('page');
    
    print header, start_html("Error"), h1("Usage $ENV{'SCRIPT_NAME'} host page"), end_html() if (!($host && $page));
    
    print header;
    print GetHTTP($host, $page);
    3)
    Code:
    do {
        $line = <SOCK>
      } until ($line =~ /^\r\n/);
      @output = <SOCK>;
      close (SOCK) || die "close: $!";
      @output;
    This whole bit is a weee bit dodgy. The $line = <SOCK> bit hasn't got a semicolon on the end, the $line variable is being overwritten all the time and is therefore useless, the loop end condition is not certain so there's a possibility of an infinite loop (this is bad), @output will not be assigned any value, and I have a feeling that just writing @output; on a line on its own may raise warnings (I could be wrong though).

    You could just do:
    Code:
    while ( <SOCK> ) { print }
    instead.

    Hope that helps a bit...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •