4

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.

3
  • no immediate answer to your question, but as postrotate uses /bin/sh and that is dash in debian nowadays (wiki.debian.org/Shell), maybe the positional parameters are not what you expect them to be. Dec 26, 2017 at 9:45
  • 1
    Did you try /root/createStats.sh $1? Remove > /dev/null for testing purpose. You can test with logrotate --debug --verbose <configfile>
    – Deeh
    Dec 26, 2017 at 19:56
  • Thank you guys. bash vs. sh did not change anything, and with debugging it did not work properly either, but the $1 parameter helped: /root/createStats.sh $1
    – hey
    Jan 14, 2018 at 10:15

1 Answer 1

10

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
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .