|
| |
|
|
womble
Posts: 6007 Joined: 3/14/2005 From: Living on the edge Status: offline
|
Crontab and "permission denied" error - 2/12/2007 17:34:05
I've made my first attempt at setting up a crontab today (not very successfully). I'm trying to back up a MySQL database. I'm using the script on this page: // database back up with email notification
// Use Crontab to automate
// make file executable
// Define your parameters,
// Best defined in a include file for security purposes
$host = "localhost";
$username = "root";
$password = "password";
$dbname = "database_name"
// define the file name
$backup = $dbname.date("Y-m-d_H:i:s").'.gz';
// define the path to the file
// we puposely do this outside the web directory
$path = "/home/username/backups/";
// combine into one string
$backup_file = $path.$backup;
// for email
$email = "myemail@domain.com";
$subject = "MySQL Dump Completed succesfully";
$body = "You MySQL back up for $backup is available at:\n\n $backup_file\n\n"
$body.= "thank you,\n Your friendly Linux Box!";
// the mysql command
$command = "mysqldump --opt -h $host -u $username -p $password $dbname | gzip > $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 = "You 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);
} (obviously with my db details) My first attempt failed abysmally - nothing at all happened, so I tried again. The PHP script is in a folder called 'backups', outside the web directory, as the page suggests, and the folder is CHMODed to 755. Second attempt at 10pm fared a little better - I got an email this time from the cron daemon: quote:
/bin/sh: line 1: /home/username/backups/database_backup.php: Permission denied (with my username in the file path) Never having tried this before, I've no idea what I'm doing really. Any suggestions anyone?
_____________________________
~~ "A cruel god ain't no god at all" ~~ ~~ Erase hate. Practice love. ~~
|
|
|
|
womble
Posts: 6007 Joined: 3/14/2005 From: Living on the edge Status: offline
|
RE: Crontab and "permission denied" error - 2/13/2007 14:41:12
Good point Jaybee. That didn't occur to me. I'll try moving it and see if it works.
_____________________________
~~ "A cruel god ain't no god at all" ~~ ~~ Erase hate. Practice love. ~~
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|