Jump to content

crontab help


aye

Recommended Posts

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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/.

Link to comment
Share on other sites

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  ;)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.