> From: [EMAIL PROTECTED] (John R. Levine)
> Date: 28 Jul 1999 11:22:56 -0400
>
> >We also saw a lot of our performance problems disappear when we moved =
> >from syslog to cyclog
>
> What do you do about daily or weekly log summaries? I still haven't
> come up with a good way to do that with cyclog.
I threw together the attached script for getting the last 24 hours worth of
logging. It could clearly be adapted for weekly as well.
If you use and and improve it in any way, I'd like to get the improvements
back.
Chris
#!/usr/local/bin/perl -w
$logdir = '/var/log';
$log = pop;
sub tailocal {
open(TAILOCAL, "|tailocal") or die "Couldn't open pipe to tailocal: $!";
foreach (@_) {
print TAILOCAL;
}
close(TAILOCAL);
}
opendir(LOGDIR, $logdir) or die "Can't read $logdir: $!";
@logs = grep { !/^\./ and -d "$logdir/$_" } readdir(LOGDIR);
#@logs = readdir(LOGDIR);
closedir(LOGDIR);
foreach (@logs) {
$logs{$_} = 1;
}
(defined $log && defined($logs{$log}))
or die "usage: $0 " . join('|', @logs) . "\n";
$logdir .= '/' . $log;
$adayago = time() - (24*60*60);
opendir(LOGDIR, $logdir) or die "Can't read $logdir: $!";
my @logs = sort grep /^\@\d+/, readdir(LOGDIR);
closedir(LOGDIR);
$lastlog = '';
foreach (@logs) {
($thislogtime) = /^\@0+(\d+)$/;
if ($thislogtime > $adayago) {
if ($lastlog) {
push @mylogs, $lastlog;
}
}
$lastlog = $_;
}
push @mylogs, $lastlog;
$firstlog = shift(@mylogs);
open(FILE, "<$logdir/$firstlog") or die "Couldn't read $logdir/$firstlog: $!";
while (<FILE>) {
($ts) = /^(\d+)/;
if ($ts > $adayago) {
#tailocal($_, <FILE>);
print $_, <FILE>;
last;
}
}
foreach $file (@mylogs) {
open(FILE, "<$logdir/$file") or die "Couldn't read $logdir/$file: $!";
@lines = <FILE>;
#tailocal(@lines);
print @lines;
}
Chris Garrigues virCIO
http://www.DeepEddy.Com/~cwg/ http://www.virCIO.Com
+1 512 432 4046 +1 512 374 0500
4314 Avenue C
O- Austin, TX 78751-3709
My email address is an experiment in SPAM elimination. For an
explanation of what we're doing, see http://www.DeepEddy.Com/tms.html
Nobody ever got fired for buying Microsoft,
but they could get fired for relying on Microsoft.
PGP signature