jellis Posted October 15, 2007 Share Posted October 15, 2007 Hi all, I've searched, copied, pasted, trialled and errored a script to run a database backup (will eventually be a CRON but I need to get the script to work effectively first). The code is below... the problem I'm having is the exec($command) is returning false and sending off a failure email to me. NOT CRICKET! Funny thing is... 50% of the time the file is actually created in the directory on the server... so the command is being executed. I've entertained (and tried) the idea of using PHP's other functions for parsing Linux commands... but they've all done the same thing. I've tried asking my TAFE (college) teachers and they've not been any help at all... $command = "/usr/bin/mysqldump --opt -h$dbhost -u$dbuser -p$dbpasswd $dbname > $backup_file"; // Now that all that is defined lets run the script if(exec($command)){// run the command if(file_exists($backup_file)){ mail($email, $subject, $body); } else { // redefine some variables for mail $subject = "MySQL Dump Failed miserably"; $body = "You MySQL back up for $backup Failed:\n\n $backup_file\n\n"; $body.= "So Sorry,\n Your friendly Linux Box!"; mail($email, $subject, $body); } } else { $subject = "Failed to execute command"; $body = "Your MySQL back up for $backup Failed to execute:\n\n $command\n\n"; $body.= "So Sorry,\n Your friendly Linux Box!"; mail($email, $subject, $body); } Looking forward to hearing your replies... Josh Quote Link to comment https://forums.phpfreaks.com/topic/73272-execvar-returning-false/ Share on other sites More sharing options...
jellis Posted October 15, 2007 Author Share Posted October 15, 2007 Sorry to whore... but I thought I should add that if I try some other Linux commands... anything really (say: ls -a) it returns true and jumps into the first tier of the "if" statement (eventually returns false because the file doesn't exist)... CONFUSED!! Quote Link to comment https://forums.phpfreaks.com/topic/73272-execvar-returning-false/#findComment-369695 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.