Forum Moderators: coopster
i am executing a php script from command line under cron job. it used to work fine before but it has started giving problems now.
here is the error i am getting when i execute it from command line
#php dump.php
sh: /mysqldump: No such file or directory
i have plesk installed on this server.
the code within my dump.php in question is as follow
exec("mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");
I tried the same using system() and shell_exec() but the same error as above. I even tried with full path as
exec("/usr/bin/mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");
but get the same error. I have checked the mysqldump and mysqldumpslow are present in /usr/bin/
when i print the above command and execute it directly from commandline then the command works fine.
I have googled a lot for this error but have failed to get any clue.
can anybody help please?
exec("/usr/bin/mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");
in my post. It means I tried to activate mysqldump from bin/ but it gives the same error. on the command line however, no matter wherever i am the same command works fine without any problem . just in the php script it gives me error.
Check:
php --info Look for these parts (and post if problem not solved):
safe_mode
safe_mode_exec_dir
Configuration File (php.ini)
Loaded Configuration File In the meantime - why not run your mysqldump command from a shell script instead of via PHP? CRON will run that just fine - dump the result to your temp file as you do now and have PHP run five minutes later to play with it if PHP processing is required.
exec("cd /usr/bin/");
exec("./mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");
Or, as suggested by vincevincevince create a shell script and call it via cron or even via another php script.
I'd put in the shell script
cd /usr/bin
./mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName
<?php
exec("/usr/bin/name.sh");
?>
Secondly, I have shown you a simple command of php script, I have a full fledge php software that runs periodically on our three servers, backs up all websites and their relative databases, then pack them into a single .tar.gz file and connect with Amazon S3 Storage service, create a new bucket by the name of current day, shift the file from our server to Amazon server, then on successful shift, remove the temporary back up files from our server to free resources.
Similarly another part of the same php software runs every 6 months to connect to amazon server, delete backup files older than last six months, to keep our amazon account free of unnecessary old back ups.
So it is a full software that I have written in PHP after very hard work of two months. I dont want to show back to this simple one line error :D try to feel for me...
anyway, I am looking to solve this to learn new thing too. because it used to work before so i have a great hope to fix it.
thank you for your replies