File split-logfile2-bymonth of Package Analog

#!/usr/bin/perl
#
# Split Apache logfile per month

use Switch;

$current_year = 2009 ;
$current_month = Sep ;

sub parse_log () {
	while (<>) {
		@line = split ( /\s+/ ) ;
		@cas = split ( /:/, $line[3] ) ;
		@datum = split ( /\//, $cas[0] );
		$year = $datum[2] ;
		$month = $datum[1]  ;

		switch ($month) {
			case Jan	{ $month = "01" }
			case Feb	{ $month = "02" }
			case Mar	{ $month = "03" }
			case Apr	{ $month = "04" }
			case May	{ $month = "05" }
			case Jun	{ $month = "06" }
			case Jul	{ $month = "07" }
			case Aug	{ $month = "08" }
			case Sep	{ $month = "09" }
			case Oct	{ $month = "10" }
			case Nov	{ $month = "11" }
			case Dec	{ $month = "12" }
		}

#		print ( "$year $current_year $month $current_month\n" ) ;
		if ( ( $year != $current_year ) || ( $current_month ne $month )) {
			$file = sprintf ( "%04d-%s" , $year , $month ) ;
			mkdir ( $file, 755 );
			open ( OUT, ">$file/access_log" ) ;
			$current_year = $year ;
			$current_month = $month ;
		}
		print OUT $_ ;
	}
}


&parse_log ();
openSUSE Build Service is sponsored by