大网数据广告活动
服务器运维问答

Logrotate postrotate: Log file name variable empty

· 52CE 我爱测

According to the logrotate manual ( https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html ), logrotate should invoke a script and hand over the filename of the rotated file as the first parameter of the script with thi…

问题原文

原帖链接 · hey · CC BY-SA 3.0

According to the logrotate manual (https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html), logrotate should invoke a script and hand over the filename of the rotated file as the first parameter of the script with this configuration:

/var/log/piwik/*.log {
    missingok
    postrotate
            /root/createStats.sh > /dev/null
    endscript
}

The createStats.sh script exists just for test purposes:

#!/bin/bash
echo "L: $1"
FNAME=/my.log
D=$(date)
echo "M $D ; $0 ; $1 ; $2" >> $FNAME

Unfortunately, my /my.log file does not contain any values for $1 (or $2):

M Tue 26 Dec 05:16:38 CET 2017 ; /root/createStats.sh ;  ;
M Tue 26 Dec 05:16:38 CET 2017 ; /root/createStats.sh ;  ;

I might be missing something. Does anyone have an idea?

My logrotate version is 3.8.7.

已采纳解答

原帖链接 · BMcG · CC BY-SA 3.0

Think of postrotate as the script. You have to pass $1 around within it. Try

/var/log/piwik/*.log {
    missingok
    postrotate
            /root/createStats.sh $1 > /dev/null
    endscript
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。