Hi, I want to be certain that my apache and varnish logfiles are in strict date order when rotated. I'd like to run a sort command against them before they're compressed. I've had a look at the logrotate man page, and it looks like I can use a postrotate/endscript to do this. However, I can see any reference in the documentation for how to operate on the file. All the examples seem to take the form of restarting something, or running some other standalone script. What I want to do is run a sort command against the newly rotated file - but how do I know what it is called? Any ideas? S.
On Monday 09 November 2009 10:00:32 am Stephen Nelson-Smith wrote:> I want to be certain that my apache and varnish logfiles are in strict > date order when rotated. ?I'd like to run a sort command against them > before they're compressed.I use the dateext option in my logrotate configuration file so that rotated files have the date appended to the filename. I also compress them so they end up like: whatever-site-access.log.20090930.gz whatever-site-access.log.20091031.gz whatever-site-error.log.20090930.gz whatever-site-error.log.20091031.gz Well...these are sorted (within the same type of file: access... error). If you want them strictly sorted by date you'll need to investigate. I'm not sure if logrotate provides any facility in order to manipulate the "current" file being rotated so maybe you'll have to do this via a shells cript & cron (after logs are rotated). HTH, Jorge
From: Stephen Nelson-Smith <stephen at atalanta-systems.com>> I want to be certain that my apache and varnish logfiles are in strict > date order when rotated. I'd like to run a sort command against them > before they're compressed. > > I've had a look at the logrotate man page, and it looks like I can use > a postrotate/endscript to do this. However, I can see any reference > in the documentation for how to operate on the file. All the examples > seem to take the form of restarting something, or running some other > standalone script. What I want to do is run a sort command against > the newly rotated file - but how do I know what it is called?I am not sure you can retrieve and cycle through the filenames that were being rotated... I would create sections for each logfile to rotate (so you know the filename)... which might be tedious if you have many log files. A script to auto-generate the logrotate conf file in /etc/logrotate.d/ will help... JD
Stephen Nelson-Smith wrote:> I've had a look at the logrotate man page, and it looks like I can use > a postrotate/endscript to do this. However, I can see any reference > in the documentation for how to operate on the file. All the examples > seem to take the form of restarting something, or running some other > standalone script. What I want to do is run a sort command against > the newly rotated file - but how do I know what it is called?How about this as an example - "/home/user/var/log/httpd/*www*log" { daily rotate 1 nocompress notifempty copytruncate missingok sharedscripts olddir /usr/local/log/httpd/archives postrotate DATE=`date --date=Yesterday +%y%m%d` cd /usr/local/log/httpd/archives for FOO in `ls *.1` do mv $FOO `echo $FOO | cut -f1 -d.`.$DATE.log done gzip -9 *.$DATE.log sleep 60 sync logger "[LOGROTATE] Rotated these logs: `echo *.${DATE}.log.gz`" endscript } nate