0

Hello guys, I don't know whats wrong I followed every tutorial for adding editing cron jobs
here is what I did.
using putty

sudo crontab -e
1 * * * * /usr/bin/php /var/www/cronjob.php

then save file,
my cronjob.php for testing perposes

$DB_HOST="localhost";
$DB_USER="root";
$DB_PASS="123456";
$DB_NAME="cron";
$connect=mysql_connect("$DB_HOST","$DB_USER","$DB_PASS") or die ("error");
mysql_select_db("$DB_NAME",$connect) or die ("error");
$sql="INSERT INTO `jobs` (
`id` ,
`job`
)
VALUES (
NULL , '3333'
)";
mysql_query($sql);

its supposed to enter "333" value in database every 1 minutes but nothing was entered
is there somthing wrong with my command ?

5
Contributors
11
Replies
52
Views
4 Years
Discussion Span
Last Post by OsaMasw
Featured Replies
  • Yes. Make sure your script is executable. Read More

  • Do this. At the top of your php script, add the line "#!/usr/bin/php" That will set the environment up so the script 'knows' what it is. Then in cron, just issue the script. 1 * * * * /var/www/cronjob.php Make sure the .php is set with execute permissions (as DoRight … Read More

0

Change both or die("error") with:

or die(error_log(mysql_error(),0));

Add one also to the query, if the id is something like int(9) not null auto_increment primary key then you don't need to declare with NULL value, otherwise it will return a boolean FALSE. After these changes check /var/log/php_errors.log or the specified file inside /etc/php5/cli/php.ini. Bye!

0

I've tried to test the php file alone and its working perfectly
I read about this and found if I want to run job every 5 minutes the command must be

*/5 * * * * /usr/bin/php /var/www/cronjob.php

but again the job not working, is the any method to test if my cron job is acually running ?

0

It will append the current date and time to the file $HOME/test every 5 minutes. ($HOME being your home directory.)

0

the code above works prefectly by writing date on file
I Need to excute php script every 5 minutes, is that possible ?

2

Do this.

At the top of your php script, add the line
"#!/usr/bin/php"

That will set the environment up so the script 'knows' what it is.

Then in cron, just issue the script.
1 * * * * /var/www/cronjob.php

Make sure the .php is set with execute permissions (as DoRight said above):
chmod +x /var/www/cronjob.php

and you should be good.

0

since he used /usr/bin/php to run cronjob.php, there is no need to put #!/usr/bin/php inside that .php script or even chmod +x it (cmiiw) - just make sure it is readable. I think cereal's idea is worth to try.

0

Good point, Marlo. Are the backticks correct in the SQL statement? I would think you would use ' not ` ?

0

thanks DoRight the error was in permission for file :d
I've changed it to excutible and its work fine, problem solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.