Cron BAD FILE MODE vs权限被拒绝 [英] Cron BAD FILE MODE vs permission denied

查看:254
本文介绍了Cron BAD FILE MODE vs权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 cron 作业来备份我的数据库:

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.

当我拥有:

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

检查 grep pg_backup.sh / var / log / cron ,我看到:

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

但是,当我将 pg_backup.sh 修改为:

chmod 644 pg_backup.sh

它禁用警告:

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

但是我看到

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

那么适当的文件权限是什么?

What are the appropriate file permissions then?

推荐答案

问题是您已将要安装的脚本安装在 /etc/cron.d 目录中。该目录用于crontab文件,而不是shell命令。 (请查看该目录中的现有文件。)

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.)

crond 中检查了其中的任何文件该目录除所有者(必须为 root )以外的其他任何人都不可读或不可写,并且任何人都不可执行。因此,您必须将权限更改为 600 或更严格的权限,以避免出现此消息-然后,如您所见,您不会能够执行脚本。

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.

相反,请将脚本放在其他位置并更新您的crontab:

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

@daily /some/other/directory/pg_backup.sh

这篇关于Cron BAD FILE MODE vs权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆