#!/usr/bin/perl -w # # Logrotate 0.1 # # Uses an external configuration file with the following syntax: # # [logfile] [versions] [pidfile] # /somedir/logfile 5 /var/pid/someapp.pid # # use strict; use Logfile::Rotate; # Change between these lines to change the default config file. #------------------------------------------- my $config = '/etc/logrotate.conf'; #------------------------------------------- our $confignr; our @config; our $appid; if (defined $ARGV[0]) { $config = $ARGV[0] } else { print "Using default configfile: $config\n"; } if (! -e $config) { syntax () } else { open(CONFIG, $config) or syntax (); @config = ; @config = grep !/^#/, @config; chomp @config; $confignr = @config; } for (my $nr = 0; $nr < $confignr; $nr++) { $_ = $config[$nr]; /^(\b)\s+(\b)\s+(\b)/; my $file = $1; my $versions = $2; my $pidfile = $3; print $file; print $versions; print $pidfile; my $log = new Logfile::Rotate( File => $file, Count => $versions, Gzip => 'lib', Post => sub{ open(IN, $pidfile); $appid = ; chomp $appid; kill("HUP", $appid); }, Dir => '/var/log/old', Flock => 'yes', Persist => 'yes',); if (defined $log) { print "Looks ok..\n"; } else { die "An error accured processing config data\n"; } $log->rotate(); undef $log; } sub syntax { print <