Cron BAD FILE MODE vs permission denied

☆樱花仙子☆ 提交于 2020-06-01 03:08:27

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/36634759/cron-bad-file-mode-vs-permission-denied

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!