Crontab and "permission denied" error (Full Version)

All Forums >> [Web Development] >> Server Issues



Message


womble -> 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?




jaybee -> RE: Crontab and "permission denied" error (2/13/2007 11:12:35)

Check with your host, you probably can't run scripts outside of the web directory for security reasons.




womble -> 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.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875