navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Crontab and "permission denied" error

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> Server Issues >> Crontab and "permission denied" error
Page: [1]
 
womble

 

Posts: 5461
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" ~~
:)
jaybee

 

Posts: 13972
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
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.

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
womble

 

Posts: 5461
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" ~~
:)

(in reply to jaybee)
Page:   [1]

All Forums >> Web Development >> Server Issues >> Crontab and "permission denied" error
Page: [1]
Jump to: 1





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