![openSUSE:Cron 日志文件上出现“权限被拒绝”错误](https://linux22.com/image/13254/openSUSE%EF%BC%9ACron%20%E6%97%A5%E5%BF%97%E6%96%87%E4%BB%B6%E4%B8%8A%E5%87%BA%E7%8E%B0%E2%80%9C%E6%9D%83%E9%99%90%E8%A2%AB%E6%8B%92%E7%BB%9D%E2%80%9D%E9%94%99%E8%AF%AF.png)
使用:openSUSE Leap 42.2
/etc/cron.d/mysite 文件内容:
* * * * * wwwrun /usr/bin/php /srv/www/mysite/cron.php >> /var/log/apache2/mysite.cron 2>&1
/etc/cron.d/目录内容:
/etc/cron.d # ls -ls
total 12
4 -rw------- 1 root root 142 May 7 2018 autologout
4 -rw-r--r-- 1 root root 289 Jan 8 14:33 mysite
4 -rw------- 1 root root 369 May 7 2018 seccheck
邮件消息:
Message 103:
From [email protected] Wed Jan 8 18:52:01 2020
X-Original-To: wwwrun
Delivered-To: [email protected]
From: "(Cron Daemon)" <[email protected]>
To: [email protected]
Subject: Cron <wwwrun@mysite1> /usr/bin/php /srv/www/mysite/cron.php >> /var/log/apache2/mysite.cron 2>&1
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=312343>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/11>
X-Cron-Env: <LC_CTYPE=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/var/lib/wwwrun>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=wwwrun>
X-Cron-Env: <USER=wwwrun>
Date: Wed, 8 Jan 2020 18:52:01 +0100 (CET)
/bin/sh: /var/log/apache2/mysite.cron: Permission denied
mysite.cron 日志文件
ls -la /var/log/apache2/mysite.cron
-rw-rw-rw- 1 wwwrun www 953 Jan 8 14:08 /var/log/apache2/mysite.cron
如何解决这个问题?
执行中
/usr/bin/php /srv/www/mysite/cron.php >> /var/log/apache2/mysite.cron 2>&1
以 root 身份从终端执行,执行良好,没有权限错误。
答案1
完美的解决方案可以在这里找到: https://serverfault.com/a/998176/302842
感谢卡梅伦·克尔 (@cameron-kerr)!