Can't figure out how to use my cron job

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Well, first off, I did use the search function and everything, Google lots of stuff, try different methods... but I can't get my cron job to work, although I am sure it's a pretty basic thing I'm trying to do.

Goal: Having a cron job that will update a particular table of my database everyday at midnight.

Query: mysql_query("UPDATE users SET actions='10'");

Pretty simple indeed... But from what I have read, I need to set my cron job to launch a script from a .php file containing my query, which I tried to do, but I got error messages such as "cannot execute binary file" and now "/home/salvatos/public_html/cgi-bin/daily_script.php: line 1: ?: No such file or directory
/home/salvatos/public_html/cgi-bin/daily_script.php: line 2: syntax error near unexpected token `('"

Here's the script I wanted to use:
Code:
<?
$connexion = mysql_connect("localhost","user","password"); 
if ( ! $connexion ) 
die ("connexion impossible"); 
$link="salvatos_rpg"; 
mysql_select_db($link) or die ("pas de connexion");
mysql_query("UPDATE users SET actions='10'");
?>

Maybe there's something wrong with it, or with my cron command:
Code:
/home/salvatos/public_html/cgi-bin/daily_script.php

The file's permissions have been set to 755, I don't know if they should be different.


Ideally, I'd like a full example of how to set up the whole thing. You have here the directories, command and php code, so you should be able to point me everything I guess. I'm willing to throw in a few credits if necessary.

Thanks in advance.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
The command for your cron job is
Code:
php -q /home/salvatos/public_html/cgi-bin/daily_script.php

(I don't know what the -q does, but I read it somewhere on the forums...)

PS:
it's probably a bad idea to put a cron script inside the public_html directory... you might want to put it in a non-public directory so nobody can execute it when it shouldn't.
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Yep, I had put it there temporarily. Now it's in /etc, I think that's what you recommended in another thread.
And your command does work like charm, thanks a lot!

For your information, I read on the web that the "-q" part prevents the cron from sending you an e-mail (of course it doesn't work if you have stuff like an echo in your script).

I have added to your reputation and closed the thread since it's resolved :)
 
Last edited:
Top