Linux – Logrotate postrotate: Log file name variable empty

linuxlogrotate

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.

Best Answer

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
}
Related Topic