aye Posted February 13, 2007 Share Posted February 13, 2007 hallo, for the last couple of days i have been trying to set up a cronjob to run a php script bur failed miserably.. ive tried all kind of things, from which ive read should work, but it does NOT. or.. not for me at least . ive also tried using wget, to run the script from the webserver, which works fine (so there is, probably, not any problem with my cron settings), but it feels more convenient running the script directly through cron rather than having wget fetch the website (takes up more resources as well maybe? after all i will run my script once every five minutes..). Ok, i will try to list all the things, that ive tried.. 1. */5 * * * * php -q /etc/crawler/index.php in crontab (dont know about that quite flag, read somewhere that you should use it with the command line version of php, which i have) 2. */5 * * * * php /etc/crawler/index.php in crontab 3. */5 * * * * /usr/bin/php /etc/crawler/index.php and */5 * * * * /usr/bin/php -q /etc/crawler/index.php in crontab 4. */5 * * * * /etc/crawler/index.php in crontab and #!/usr/bin/php -q / #!/usr/bin/php on the first line of the php script ok, now im quite new to running php scripts through cron (actually its my first time ), so ive probably forgotten to add something.. any ideas? help would be greately appreciated Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/ Share on other sites More sharing options...
trq Posted February 13, 2007 Share Posted February 13, 2007 if you are able to access and run the script via wget then it is highly unlikely that /etc/crawler/index.php is a valid path to your script. Are you on a dedicated or shared server? Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183587 Share on other sites More sharing options...
aye Posted February 13, 2007 Author Share Posted February 13, 2007 hi, im using a dedicated server and ive access to all directorys. sorry if i was unclear, but when running the script from wget, im running the script from a different location (/var/www/html/crawler/index.php). in any case, if i run "php /etc/crawler/index.php" from terminal, the script runs as it should, which confuses me even more; isnt that the exact line cron should run as well? Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183606 Share on other sites More sharing options...
trq Posted February 13, 2007 Share Posted February 13, 2007 isnt that the exact line cron should run as well Yes. If you place the shebang (#!/usr/bin/php -q) on the very first line of the script you will however not need to tell cron which application (php) to run the file with. Are you sure php is in /usr/bin/php? Sometimes it can be in /usr/local/bin/php. Also, make sure the file has execute permissions (I'm sure you have already). Take a look at your logs to see what cron has to say..... sudo grep cron /var/log/messages | tail -50 PS: Keeping a script in /etc is a bad idea. Its just not the right location for it. Ide put the script within /usr/local/bin/. Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183610 Share on other sites More sharing options...
aye Posted February 13, 2007 Author Share Posted February 13, 2007 Are you sure php is in /usr/bin/php? Sometimes it can be in /usr/local/bin/php. Also, make sure the file has execute permissions (I'm sure you have already). yeap, used 'which php' to get the php path. file permissions is 755 Take a look at your logs to see what cron has to say..... sudo grep cron /var/log/messages | tail -50 this is the cron output: Feb 13 15:45:01 c80-217-170-126 crond[31151]: (root) CMD (php /etc/crawler/index.php) PS: Keeping a script in /etc is a bad idea. Its just not the right location for it. Ide put the script within /usr/local/bin/. ok, ill change that. not very good at linux directorys Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183625 Share on other sites More sharing options...
trq Posted February 13, 2007 Share Posted February 13, 2007 If that is the output of your log, then by all rights the script is running. How exactly are you determining that it is not running? And can we see the script? Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183640 Share on other sites More sharing options...
aye Posted February 13, 2007 Author Share Posted February 13, 2007 ok, i put a simple mysql query in my script to see if it actually was running and yes, youre right, it is running.. anyhow, its an indexing script, looking for links on the net to certain files and then downloading them to the server. its quite an intricate script with above 1000 lines of code (in 13 separate files), so i dont feel like posting it here . ok, so the script is running, but normally it indexes about thousand files / day with wget, but now, after two days running directly from cron, it hasn't indexed a single file! could there be any port problems when not run from the webserver or something? Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183846 Share on other sites More sharing options...
trq Posted February 13, 2007 Share Posted February 13, 2007 If the code is within several files the issue is probably a path problem. Are you including these files into this original file which cron calls? You'll need to use absolute paths when dealing with cron. Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-183923 Share on other sites More sharing options...
aye Posted February 14, 2007 Author Share Posted February 14, 2007 ah, so.. if i would use include or require, i have to write the full path, like require_once("/etc/crawler/config.php")? Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-184579 Share on other sites More sharing options...
trq Posted February 15, 2007 Share Posted February 15, 2007 Yep. Otherwise, and easier solution might be to wrap the call to your script in a bash script. eg; /usr/bin/crawler.sh #!/bin/bash if [[ -d /etc/crawler ]] ; then cd /etc/crawler if [[ -x index.php ]] ; then php -q index.php fi fi exit 0 Then just have cron call this script. eg; */5 * * * * /usr/bin/crawler.sh Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-185043 Share on other sites More sharing options...
aye Posted February 15, 2007 Author Share Posted February 15, 2007 wow, thank you so much!! it works great! youve really made my day now Quote Link to comment https://forums.phpfreaks.com/topic/38304-crontab-help/#findComment-185586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.