#!/usr/local/bin/perl # # distlog.pl - break down log file in common log format by day # Copyright (C) 2002 - Anthony Tonns # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # --- # i am not a robust script # please do not put me in a crontab #my $datestyle = "old"; my $datestyle = "new"; $|=1; %months = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12", ); my $log; foreach $log (@ARGV) { my (@fullpath) = split(/\//,$log); my ($filename) = pop(@fullpath); my ($basename,$extention) = split(/\./,$filename); my ($outf) = "none"; my $linecnt = 0; open(LOG,"<$log") || die "no log file $log"; while() { $linecnt++; next if $linecnt == 1; my($line) = $_; my($datetime) = ($line=~/^[^[]*\[([^]]+)\]/); my($date,$time) = split(/:/,$datetime,2); my($day,$mon,$year) = split("/",$date); my($shortyear) = substr($year,2,2); my($month) = $months{$mon}; my($myfile) = "${year}${month}${day}.$basename"; if ( $datestyle eq "old" ) { $myfile = "${month}${day}${shortyear}.$basename"; } if ( $outf ne $myfile ) { if ( $outf ne "none" ) { close OUT; } print "switching from $outf to $myfile\n"; $outf = $myfile; open(OUT,">>$outf") || die "cannot write to $outf"; } if ( ( $linecnt % 1000 ) == 0 ) { print "."; } print OUT $line; } close LOG; }