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?
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?
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...
yeah that could not be possible coders never make mistakes 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.
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.....
Shell scripts would work fine if the directories are relative from WHERE they are called, otherwise use the absolute paths. Peace,
As such, usually absolute paths work better As cron is in complete different directory located usually than the web root itself
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?)
When you're creating the script, make use of the $_SERVER('DOCUMENT_ROOT') variable. This will give you the base directory for your website. Then just create your cron script starting with cwd $_SERVER('DOCUMENT_ROOT'); http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.server
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.
urm, cron is executed as you, from your home dir, NOT html root, so yeah absolute paths are necessary ....
Confused. Are we talking about *generating* a script for cron within a script? Or is this something external or parallel to the website?