cron job gives me permission denied errors when running

8,969
chmod +x /disk1/archives/backup.*.cron

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 with crontab /disk/1/archives/backup, but the backup file you showed us specifies the root user on each line. But your crontab -l output doesn't show the root user name.

The error message you're getting is consistent with the crontab -l output (if the file you gave to crontab had the root username, it would attempt to execute root as a command). I presume the actual file you fed to crontab doesn't have the root fields.

man 5 crontab for information about the difference between normal and system cron files.

Share:
8,969

Related videos on Youtube

Eli
Author by

Eli

Updated on September 18, 2022

Comments

  • Eli
    Eli over 1 year

    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?

    • kaji
      kaji about 12 years
      is there /web ? and also please replace commands with full path since cron runs in limited PATH
  • Eli
    Eli about 12 years
    sorry for the late reply, your right. i got 2 clipboards confused when i pasted. The crontab doesn't have the root issued. So you are are saying that I need to chmod +x the backup.*.cron rather than the backup file that has the cron job rules.