Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Jun 2001 11:38:05 +0300
From:      Krassimir Slavchev <krassi@bulinfo.net>
To:        Jan Knepper <jan@digitaldaemon.com>, FreeBSD-ISP <freebsd-isp@freebsd.org>
Subject:   Re: Log file rotation with Apache.
Message-ID:  <3B1DEBED.B7C40AEA@bulinfo.net>
References:  <3B13D6DC.5040201@digitaldaemon.com> <3B1DEB36.A49DB40A@bulinfo.net>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Ooops, forgot attachment:( Sorry!

Krassimir Slavchev wrote:

> Hello All,
>
> See attachment!
> This perl script is not perfect, but will do all necessary.
>

--
 Krassimir Slavchev           Bulinfo Ltd.
 krassi@bulinfo.net           (+359-2)963-3652
 http://www.bulinfo.net       (+359-2)963-3764



[-- Attachment #2 --]
#!/usr/bin/perl

###_________________________________________(c) DieselOS

## Structure of rotate.conf file (for example)
## logfile             count   size_in_Kbytes
#/var/log/access.log   3       1024 
#

use strict;

# Change paths if differ!
my $conf_file	= "/etc/rotate.conf";
my $MV		= "/bin/mv";
my $GZIP	= "/usr/bin/gzip";

my ($logfile, $count, $size, $i, $n);
open(FILE, "<$conf_file") || die "Can not open file: $conf_file!\n";
while(<FILE>)
{
 next if /^#/;         # Commented line !
 s/^\s+//;
 s/\s+$//;
 next unless $_;
 ($logfile, $count, $size) = split(/\s+/, $_);

  if (-s $logfile > $size * 1024)    # rotate if size exceed (in Kbytes!)
   {
    for ($i = $count-1; $i > 0; $i--)
     { 
      $n = $i-1;
      if (-e "$logfile.$n.gz")
       {
        `$MV $logfile.$n.gz $logfile.$i.gz`;
       }
     }
    `$GZIP -c $logfile > $logfile.0.gz;>$logfile`;
   }
}
close FILE;


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B1DEBED.B7C40AEA>