Been trying to run a cron but keep getting permission died error in my /var/spool/mail/root
"/bin/sh: /disk1/archives/backup.website.cron: Permission denied"
This is my ls -hal
for the directory my cron jobs are in
drwxr-xr-x 4 root root 4.0K Feb 6 04:22 .
drwxr-xr-x 6 root root 4.0K Feb 5 08:14 ..
-rwxr-xr-x 1 root root 105 Feb 6 04:22 backup
-rw-r--r-- 1 root root 102 Feb 5 08:34 backup.database.cron
-rw-r--r-- 1 root root 75 Feb 5 08:33 backup.website.cron
drwxr-xr-x 2 root root 4.0K Feb 5 08:35 databases
I have backup
set to chmod +x
The backup file looks like this
* * * * * root /disk1/archives/backup.website.cron
30 * * * * root /disk1/archives/backup.database.cron
I ran the cron with
crontab /disk/1/archives/backup
I can see that my cron jobs are set up to run because when I do crontab -l
I get
[root@web archives]# crontab -l
* * * * * /disk1/archives/backup.website.cron
30 * * * * /disk1/archives/backup.database.cron
backup.website.cron looks like
tar -zcvf /disk1/archives/websites/`date +%Y-%m-%d_%I:%M:%S%p`.tar.gz /web
while backup.website.cron looks like
mysqldump --opt --all-databases | gzip > /disk1/archives/databases/`date +%Y-%m-%d_%I:%M:%S%p`.sql.gz
am i missing a permission change somewhere?
am i running the correct scripts thru the crontab?
The file that you feed to
crontab
command doesn't need to be executable, since it isn't a shell script. Any commands that you invoke as cron jobs do need to be executable.There's another oddity here. There are two slightly different syntaxes for crontab. One has 5 fields that specify when the command is to be executed, followed by the command itself; this is the format that the
crontab
command expects. The other adds a username between the 5 time fields and the command. This is the format used by/etc/crontab
, and by files under the/etc/cron.*
directories. (That's on Ubuntu 11.04; the organization might differ slightly on other systems.)You said you installed your
backup
file withcrontab /disk/1/archives/backup
, but thebackup
file you showed us specifies theroot
user on each line. But yourcrontab -l
output doesn't show theroot
user name.The error message you're getting is consistent with the
crontab -l
output (if the file you gave tocrontab
had theroot
username, it would attempt to executeroot
as a command). I presume the actual file you fed tocrontab
doesn't have theroot
fields.man 5 crontab
for information about the difference between normal and system cron files.