I am having trouble with the prerotate script in logrotate 3.12.2. The script I specify in the prerotate/endscript
section is not receiving the name of the file to be rotated as the first argument ($1
).
Here is the logrotate configuration:
compress
/external-logs/syslog {
daily
rotate 3
olddir OLD
missingok
prerotate
/root/filter-syslog.sh
endscript
}
Here is /root/filter-syslog.sh
:
#!/bin/sh
echo "log file subject to prerotate: $1"
Finally, here is the verbose output of the logrotate run:
reading config file /external-config/logrotate.conf
olddir is now OLD
Reading state from file: /external-logs/logrotate.state
Allocating hash table for state file, size 64 entries
Creating new state
Handling 1 logs
rotating pattern: /external-logs/syslog after 1 days (3 rotations)
olddir is OLD, empty log files are rotated, old logs are removed
considering log /external-logs/syslog
Now: 2017-09-24 13:35
Last rotated at 2017-09-23 12:50
log needs rotating
rotating log /external-logs/syslog, log->rotateCount is 3
dateext suffix '-20170924'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /external-logs/OLD/syslog.3.gz to /external-logs/OLD/syslog.4.gz (rotatecount 3, logstart 1, i 3),
old log /external-logs/OLD/syslog.3.gz does not exist
renaming /external-logs/OLD/syslog.2.gz to /external-logs/OLD/syslog.3.gz (rotatecount 3, logstart 1, i 2),
old log /external-logs/OLD/syslog.2.gz does not exist
renaming /external-logs/OLD/syslog.1.gz to /external-logs/OLD/syslog.2.gz (rotatecount 3, logstart 1, i 1),
old log /external-logs/OLD/syslog.1.gz does not exist
renaming /external-logs/OLD/syslog.0.gz to /external-logs/OLD/syslog.1.gz (rotatecount 3, logstart 1, i 0),
old log /external-logs/OLD/syslog.0.gz does not exist
log /external-logs/OLD/syslog.4.gz doesn't exist -- won't try to dispose of it
running prerotate script
log file subject to prerotate:
renaming /external-logs/syslog to /external-logs/OLD/syslog.1
compressing log with: /bin/gzip
Note the line "log file subject to prerotate:
" in the above output. Why isn't the line output "log file subject to prerotate: /external-logs/syslog
" instead?
You are not passing anything to your shell script. So
$1
in your/root/filter-syslog.sh
has no value and therefore nothing is printed.To make it work, you have to pass
$1
or$@
in your logrotate configuration.