我运行sudo crontab -e
并附加以下行:
* * * * * logrotate -f /etc/logrotate.d/adraw; touch /ADraw/Data/Logs/test.txt
文件 test.txt 已成功创建,但我看不到 logrotate 的结果。奇怪的是,如果我运行,sudo logrotate -f /etc/logrotate.d/adraw
一切都正常(创建了其他文件)。
我的/etc/logrotate.d/adraw
配置:
/ADraw/Data/Logs/*.log {
hourly
size 1M
missingok
rotate 5
compress
delaycompress
notifempty
create 0640 ADraw ADraw
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi \
endscript
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
}
答案1
正如steeldriver所说,解决方案是在cron中向logrotate添加完整路径:
* * * * * /usr/sbin/logrotate -f /etc/logrotate.d/adraw; touch /ADraw/Data/Logs/test.txt