抱歉英語程度低
在我的臨時伺服器中
我想要每天進行 logrotate(nginx)
所以我創建 logrotate 文件/etc/logrotate.d/
/etc/logrotate.d/nginx
/var/log/nginx/*log {
create 0644 nginx nginx
daily
rotate 30
missingok
notifempty
nocompress
dateext
dateformat -%Y%m%d
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
我將 logrotate 文件插入cron.daily
/etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate -f /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with
[$EXITVALUE]"
fi
exit 0
我檢查/etc/anacrontab
/etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
我檢查ls -la /var/spool/anacron/cron.daily
/var/spool/anacron/cron.daily
20180221
nginx 日誌會這樣輪轉access.log, access.log-20180222
但當我命令run-parts /etc/cron.daily
它不起作用...
奇怪的是,當我插入命令列時/usr/sbin/logrotate -f /etc/logrotate.conf
它工作得很好!
我認為/etc/cron.daily/logrotate
沒有執行時run-parts /etc/cron.daily
但是在我本地的docker中我命令run-parts /etc/cron.daily
,它有效
只有臨時伺服器無法工作,,
為什麼/etc/cron.daily/logrotate
當我命令時文件不起作用run-parts /etc/cron.daily
?
答案1
問題解決了
這是權限問題
chmod 700 logrotate
-rw------- logrotate
->-rwxr--r-- logrotate
效果很好