Jump to content
xisto Community
Sign in to follow this  
CrazyRob

Cron Job Question

Recommended Posts

Ok i need to execute an sql query at a certain time of day and they only way i think this can be achieved is through a cron. The only problem is that i haven't a clue how to do it.

Code:

UPDATE trap17_ipbmembers SET points = points - 1 WHERE mgroup = 3

thats the SQL code but i need that executed at a certain time on a certain database every day. can anyone help me as i have know knowledge of cron what so ever - have a fealing i need to do that database bit in php but im not sure what code to put in as it will interact with cron.
Help...

Share this post


Link to post
Share on other sites

I am assuming your not using cpanel, if you are you could set them up that way. any ways I thought I toss this little code up for you

https://www.sitepoint.com/introducing-cron/

it's a series of php scripts and some mysql that should get it going for you.

Share this post


Link to post
Share on other sites

well i am using cpanel. cpanel cant execute sql queries from cron so id need a php script that had all the data in it then set cron to run the php script at a certain time of day

Share this post


Link to post
Share on other sites

Yup. You need to get the cron job to run the PHP

I use something like this.

0 0 * * * /usr/bin/php -q /home/yacoby/public_html/path/to/php/file.php > /dev/null

(If you set up the cron job under the Unix style interface, you will see that there are boxs for the 0s and *s, and then one big text input for this:
/usr/bin/php -q /home/yacoby/public_html/path/to/php/file.php > /dev/null

/usr/bin/php
This is the path to PHP.

-q
Quite. The > /dev/null might make it so you don't need this.

/home/yacoby/public_html/path/to/php/file.php
The path from your top directory to the PHP file

> /dev/null
I think this makes it so that the output is deposed of. Not sure though.



Inclding something like this:
if ($REQUEST_URI){	print "Access forbidden!<br>";	exit;}

At the top of the script would, I think, make it so the script can't be run from your browser, it has to be run via the cron job.


Hopefully this will have helped. I don't know very much at all on this subject.
Edited by Yacoby (see edit history)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.