I would like to request an option that acts like sharedscripts but doesn't run the scripts if no logs are to be rotated. I would use this to run a Perl script that looks for Code Red/Nimda/etc. signatures in access_log before rotating it. Since the latest apache version uses the sharedscripts option in /etc/logrotate.d/apache, I get a report every day instead of once a week. I can (and have) split off access_log into its own section, but then I'm HUPping apache twice rather than once. It would be more efficient to have an option (say "sharedscriptsonlyifrotate") as described above. I could even deal with an option that always runs the prerotate but only runs the postrotate if a log was rotated (which I suspect is easier to program).
Sounds like a nice idea. Unfortunately, since logrotate is at the bottom of the food chain, I'm not likely to be able to implement it in this lifetime. "Patches welcome", or something - perhaps asking on redhat-devel-list might find a volunteer to write the patch.
Apparently a common desire for logrotate is to have a bunch of log files that one wishes to rotate (e.g., from syslogd), but only SIGHUP syslogd when one or more files need rotating. I offer the following scripts (as part of a logrotate config file) that not only do the job, but allow custom processing of some of syslogd's files without SIGHUPing syslogd multiple times. This uses an undocumented feature of logrotate to pass the rotated file name to the script as the first ($1) parameter; /var/log/syslog/*.log { prerotate echo $1 >>/var/state/logrotate/syslog endscript } /var/state/logrotate/syslog { daily # MUST be daily, as logs can rotate any day of the week rotate 1 # (or zero, or any other number) notifempty # This is the key to only running if rotation occurred. prerotate /bin/killall -HUP syslogd for f in `cat $1`; do case $f in /var/log/syslog/kernel.log) # special stuff to parse kernel.log.1 (AKA $f.1) here ... ;; esac done endscript }
Does logrotate always process logs in the order listed? In what order are the /etc/logrotate.d files processed?
Logrotate processes logrotate config files in the order it finds them in the /etc/logrotate.d directory (which can appear random), but within a lorotate config file, the actions are processed in order of specification (according to my reading of the code, my experience, and the assurance of ewt @redhat.com -- the original author of logrotate).
Send patches