Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a cron job:

#!/bin/bash 
fn=db.backup.$(date +%m-%d-%y).sql
mysqldump -uMyUsr -pMyPass --add-drop-table dbName> $fn
find ./ -name '*.Z' -type f -mtime +7 -exec rm -f {} \;

I get an error:

/backup.sh: line 3: db.backup.10-24-12.sql: Permission denied
db.backup.10-24-12.sql: No such file or directory
find: ./conf: Permission denied
find: ./pd: Permission denied

It looks like whatever process is running cron doesn't have permissions to create a file or to run 'find' command.

share|improve this question
    
what are the permissions of the directory it is running in? –  h3rrmiller Oct 24 '12 at 13:35
    
the backup.sh is running in 'sqlbackup' directory that has 777 or rwx for all. –  dev.e.loper Oct 24 '12 at 13:37
add comment

1 Answer

up vote 2 down vote accepted

you should use:

fn=/full/path/to/db.backup.$(date +%m-%d-%y).sql

or

cd /full/path/to/

before you export the database

unless your cronjob looks like:

* * * * * cd /full/path/to && backup.sh
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.