gpt4 book ai didi

linux - 通过 cron 以 root 身份记录旋转 "Permission Denied"

转载 作者:太空宇宙 更新时间:2023-11-04 12:56:52 24 4
gpt4 key购买 nike

我正在尝试配置一个自定义的 logrotate 策略以作为 root 每分钟运行一次。不幸的是,cron 作业拒绝了我的许可;但如果我以 root 身份手动运行脚本,我不会遇到任何问题。

custom_logrotate.sh

#!/bin/bash

/usr/sbin/logrotate -f -v /etc/custom_logrotate/custom_logrotate.conf > /var/log/rotate.log 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

/etc/cron.d/custom_logrotate

* * * * * root /etc/custom_logrotate/custom_logrotate.sh

custom_logrotate.conf

/opt/nginx/logs/stdout.log /opt/nginx/logs/perf.log {
rotate 10
copytruncate
nocompress
size 10M
start 0
}

权限

namei -mo /opt/nginx/logs/
f: /opt/nginx/logs/
dr-xr-xr-x root root /
drwxr-xr-x root root opt
drwxr-x--- root gnginx capione
drwxr-x--- root gnginx logs

以及错误信息。

error: error opening /opt/nginx/logs/perf.log: Permission denied

注意:直接运行/etc/custom_logrotate/custom_logrotate.sh 工作正常,但面临来自 cron 作业的问题。

最佳答案

问题在于使用 /etc/cron.d 而不是 /var/spool/cron/root aka crontab。

似乎即使在 /etc/cron.d 中将用户指定为 root,一些实用程序仍然无法正常工作。

关于linux - 通过 cron 以 root 身份记录旋转 "Permission Denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com