3

I have a cron job for backuping my databases:

➜  ~ crontab -l
@daily /etc/cron.d/pg_backup.sh

There is a problem with setting appropriate permissions, though.

When I have:

➜  ~ ls -l /etc/cron.d/pg_backup.sh
-rwxr-xr--. 1 root root 1359 Apr 14 21:39 /etc/cron.d/pg_backup.sh

and then check grep "pg_backup.sh" /var/log/cron, I see:

localhost crond[11881]: (root) BAD FILE MODE (/etc/cron.d/pg_backup.sh)

However, when I modify pg_backup.sh as:

chmod 644 pg_backup.sh

It disables the warning:

localhost CROND[11064]: (root) CMD (/etc/cron.d/pg_backup.sh)

but I see

➜  ~ cat /var/mail/root
# ...
/bin/sh: /etc/cron.d/pg_backup.sh: Permission denied

What are the appropriate file permissions then?

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90

1 Answers1

5

The problem is that you've installed the script to be executed in the /etc/cron.d directory. That directory is for crontab files, not shell commands. (Take a look at the existing files in that directory.)

There's a check in crond that any files in that directory are not readable or writable by anyone other than the owner (which must be root), and are not executable by anyone. So you'd have to change the permissions to 600, or to something even stricter, to avoid the message -- and then, as you've seen, you wouldn't be able to execute the script.

Instead, put the script somewhere else and update your crontab:

@daily /some/other/directory/pg_backup.sh
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631