Newbie Perl question

Discussion in 'Programming' started by sarahk, Oct 19, 2004.

  1. #1
    My webhost has cPanel which only accepts Perl scripts, aargh

    So I'm using this to get Perl to call my real PHP scripts which do all the work

    #!/usr/local/bin/perl -w
    use LWP::Simple;
    use CGI;
    my $URL="[url="http://www.mysite.com/myscript.php"]http://www.mysite.com/myscript.php[/url]";
    my $content = LWP::Simple::get($URL);
    print "$content";
    Code (markup):
    I have 2 cron jobs, 2 Perl scripts and 2 PHP scripts.

    Both the PHP scripts are called using the full URL even though one is on the same server. Both PHP scripts will work if called directly.

    Now, one of the Perl scripts works, but the other doesn't. I get


    sent to me by the cron job. If I call it in the browser I get a 500 error. Line 10 is the print "$content"; statement.

    Any ideas why it might decide to fall over?

    Sarah
     
    sarahk, Oct 19, 2004 IP
  2. flawebworks

    flawebworks Tech Services

    Messages:
    991
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    78
    #2
    You can't use php? They just don't offer it?
    Clarification: you're calling the perl script in a cron job; right?

    Have you checked your perms? 500 error is a permissions error; check to make sure that if it's a perl script; perms are 755, make sure the script was uploaded in ascii mode; not binary, and don't use dreamweaver to edit the script.


    If the script is a php script; sometimes setting the perms to 777 does the trick.

    This sounds like you have funky characters in the perl script itself. YOu can't see it; but if you sshd into your box and did a vi filename you could.
     
    flawebworks, Oct 19, 2004 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Thanks for the reply.

    I can use PHP on the site, but I can't get the Cron to call PHP. I'm happier with PHP so I figured I'd just get the Perl script to fire up the PHP script and I can code merrily away in there.

    I have another server where I don't have cron and I need to get info from it, so my first perl script calls a PHP script on that server. Getting this up and running was painless.

    The second perl script is a copy, literally, of the first, with just the page changed. I give the full domain and page. I can run the PHP script manually, no probs. Perl scripts are set to upload as Ascii but to be sure I uploaded it again. The settings were 755, now 777, no change.

    I tried running the perl script on another server which I could also vi the script and there are no stray characters. It's very clean. On that server I got a 403 error, not a 500 error and I'm not sure quite what the problem was... The important thing was that there were no funky characters.

    This is really frustrating - because it should be so simple :)

    Sarah
     
    sarahk, Oct 19, 2004 IP
  4. flawebworks

    flawebworks Tech Services

    Messages:
    991
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    78
    #4
    If you are on a cpanel server; and want to run a cron script for php; do this.

    You can either log into the cron area of cpanel; or ssh.

    Use a path like this:

    GET http://yourdomainname.com/path to/file.php
     
    flawebworks, Oct 19, 2004 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Thanks for the hint flawebworks

    but GET just returned me my source code, it didn't RUN the code.

    Sarah
     
    sarahk, Oct 19, 2004 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #6
    flawebworks you gave me just the hint I needed. Thank you! I did a hunt around and it seems that instead of GET I needed php. Took a while to find the documentation but I'm up and running, woohoo!

    Sarah
     
    sarahk, Oct 19, 2004 IP
  7. flawebworks

    flawebworks Tech Services

    Messages:
    991
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    78
    #7
    You go girl! Sometimes it does require a bit of playing around with.
     
    flawebworks, Oct 19, 2004 IP
  8. aenigma

    aenigma Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    aenigma, Oct 20, 2004 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #9
    It didn't like WGET when I tried that

    since it's happy with PHP I'll let stay with that. It's been happily working every hour today, no problems, just a happily updating site and an unstressed server. :)

    Sarah
     
    sarahk, Oct 20, 2004 IP
  10. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #10
    Some people know just how to soften me up
    Well...

    Use the script I have at the very top of this thread and get it to call your PHP script. The PHP script does all the work and will do the job if called from a regular browser. Generally they will only output debugging or verification data, in plain text, not html.

    The perl just calls the PHP for you and nothing else.

    Sarah
     
    sarahk, Jun 7, 2005 IP