Koozali.org: home of the SME Server

making cron run a php file

cyberdude

making cron run a php file
« on: February 27, 2005, 12:01:52 PM »
Hi

I am in the process of setting up some database backup / dump on my SME and cant figure out how to get cron to activate a php file

I have the following code in my php file
<?
$nu = time();
exec('mysqldump --databases my_db --add-drop-table > /home/e-smith/files/ibays/hg_/files/backup$nu.sql');
?>

And when the cron passes the comand for this script it just outputs this error:
/home/e-smith/files/ibays/ddpnet_/html/dbdump.php: ? : No such file or directory
/home/e-smith/files/ibays/dd_/html/dbdump.php: line 2: syntax error near unexpected token time()'
/home/e-smith/files/ibays/dd_/html/dbdump.php: line 2: $nu = time(); '

If i just enter this in the file
mysqldump --databases my_db --add-drop-table > /home/e-smith/files/ibays/hg_/files/backup.sql

it outputs the backup / dump file with no errors

The cron job entery look like this
#(db dump 2)
45 * * * * root /home/e-smith/files/ibays/dd_/html/dbdump.php

I want to add the timestamp to EVERY file, or just the timestamp.sql for the filename

But how shoud the script looks like when i'm not able to just run the php script?
is it posible to set up in a non php file or how ??

Offline Curly

  • ****
  • 114
  • +0/-0
making cron run a php file
« Reply #1 on: February 27, 2005, 07:55:16 PM »
You should explain to linux, that you want php to run the script, so start the script with:

#!/usr/bin/php -q
<?php

Or, you can change the cron entry to something like:

45 * * * root /usr/bin/php -q home/e-smith/files/ibays/dd_/html/dbdump.php





Code: [Select]
.......................................

cyberdude

making cron run a php file
« Reply #2 on: February 27, 2005, 09:30:00 PM »
hi...

If i put the
#!/usr/bin/php -q

I get this error for the corn:
/bin/bash: /home/e-smith/files/ibays/dd_/html/dbdump.php: /usr/bin/php: bad interpreter: Permission denied

But if i put it directly in the cron job line like this :
16 * * * * root /usr/bin/php -q /home/e-smith/files/ibays/dd_/html/dbdump.php

It went almost okay, except i got a php warning mail...
Failed loading /usr/lib/php4/php_accelerator_1.3.3r2.so:  /usr/lib/php4/php_accelerator_1.3.3r2.so: cannot open shared object file: No such file or directory

I know that this "bug" come up becourse that on the server the script is running the php file i miored from another server with this script installed, and it is not (yet) installed on this server

So what the diferent is between this 2 options you posted is and why only the one worked for me i dont know, but tha fackt is that itøs working :-)

Thanx
Quote from: "Curly"
You should explain to linux, that you want php to run the script, so start the script with:

#!/usr/bin/php -q
<?php

Or, you can change the cron entry to something like:

45 * * * root /usr/bin/php -q home/e-smith/files/ibays/dd_/html/dbdump.php

Code: [Select]