]> mj.ucw.cz Git - libucw.git/blob - ucw/utils/ucw-rotate-log.pl
XTypes: CF_XTYPE requires '&' before xt_*, just like most other parameters in CF_...
[libucw.git] / ucw / utils / ucw-rotate-log.pl
1 #!/usr/bin/perl
2
3 #       Rotate Sherlock logs
4 #       (c) 2001--2002 Martin Mares <mj@ucw.cz>
5
6 use File::stat;
7
8 @ARGV >= 3 or die "Usage: ucw-rotate-log <days-to-compress> <date-to-delete> <logs...>";
9
10 $now = time;
11 $cps = shift @ARGV;
12 $del = shift @ARGV;
13
14 $compress_thr = $now - 86400 * $cps;
15 $delete_thr = $now - 86400 * $del;
16 foreach $f (@ARGV) {
17         -f $f or next;
18         $st = stat $f or next;
19         if ($del > 0 && $st->mtime < $delete_thr) {
20                 print "Deleting $f\n";
21                 unlink $f || die "Delete FAILED: $!";
22         } elsif ($cps > 0 && $st->mtime < $compress_thr && $f !~ /\.(gz|bz2)$/) {
23                 print "Compressing $f\n";
24                 `gzip -f $f`;
25                 $? && die "Compression FAILED: $!";
26         }
27 }