Does CRON need absolute paths?

Discussion in 'PHP' started by giorgioarmani, Feb 4, 2007.

  1. #1
    I have this script where I need to set one file up as CRON.

    However Ive been trying everything for months and nothing works.

    Now the host tells me "I cant do it with this script because it is using some include paths and these are relative. Relative will work fine using the browser but cannot work with CRON."

    Is this so?
     
    giorgioarmani, Feb 4, 2007 IP
  2. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, you should use absolute paths :)
    Are you UNIX based hosted ? (linux, etc) Or Windows-based?
    And the script you have to link to with Cron, is it PHP, CGI, ASP or something else? :)
     
    DeViAnThans3, Feb 4, 2007 IP
  3. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Hi DeViAnThans3, thx for your answer..

    The server is linux and the script is a PHP script.

    Im surprised that the script would be written using relative paths, if CRON needs absolute paths...

    Mistake from the coder? I couldnt imagine that...
     
    giorgioarmani, Feb 4, 2007 IP
  4. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yeah that could not be possible coders never make mistakes :p

    I've experienced this also. I think the reason CRON needs absolute paths is that it's not running the script from the directory where the script actually is. So if you try and include a file or something - the path will be wrong.

    Also doing things like
    include ("../file.php"); does not work on some servers - but I've had it work on others from CRON.

    It should not be to much trouble to modify the script to have absolute paths. And is usually the safest thing to do when writing scripts that need to be run from CRON.



    Red.
     
    rederick, Feb 4, 2007 IP
  5. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Wow guys, if this is the reason it hasnt worked for the last 3 months and neither host nor coder could tell me the reason until yesterday then this has made my day! Lets wait and see if coder will agree with what host says.....
     
    giorgioarmani, Feb 4, 2007 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Shell scripts would work fine if the directories are relative from WHERE they are called, otherwise use the absolute paths.

    Peace,
     
    Barti1987, Feb 5, 2007 IP
  7. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #7
    As such, usually absolute paths work better ;)
    As cron is in complete different directory located usually than the web root itself :)
     
    DeViAnThans3, Feb 5, 2007 IP
  8. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Can't you call your cron scripts via wget - this way you'd call them using a "browser" and all your paths problems would be solved (since I guess the PHP script do work, in a browser, right?)
     
    picouli, Feb 5, 2007 IP
  9. pbmods

    pbmods Guest

    Messages:
    18
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    pbmods, Feb 5, 2007 IP
  10. aplus

    aplus Well-Known Member

    Messages:
    83
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    115
    #10
    You need to use absolute paths. And if the script you are trying to run includes another script, then this path will also have to be absolute.
     
    aplus, Feb 6, 2007 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    urm, cron is executed as you, from your home dir, NOT html root, so yeah absolute paths are necessary ....
     
    krakjoe, Feb 6, 2007 IP
  12. pbmods

    pbmods Guest

    Messages:
    18
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Confused. Are we talking about *generating* a script for cron within a script? Or is this something external or parallel to the website?
     
    pbmods, Feb 6, 2007 IP
  13. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #13
    Thanks for all your replies guys, the absolute path solved it!
     
    giorgioarmani, Feb 9, 2007 IP