Jump to content

exec($var) returning false


jellis

Recommended Posts

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

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.