#!/usr/bin/perl # # logsplit.pl # Miguel A.L. Paraz # # logsplit.pl ip-list-file output-file1 output-file2 # Reads Apache access log from stdin # Outputs the local IP's to output-file1, the rest to output-file2 # # Requires Net::Patricia module from CPAN use strict; use Net::Patricia; my $ip_list_file = $ARGV[0]; my $output_file1 = $ARGV[1]; my $output_file2 = $ARGV[2]; # Load the Patricia trie my $pt = new Net::Patricia; open (H, $ip_list_file) || die ($! . " " . $ip_list_file); while (defined (my $line = )) { chomp ($line); my @a = split (/\s+/, $line); if ($a[0] && $a[1]) { $pt->add_string($a[0], $line); } } close (H); # Open the two output files open (H1, ">>" . $output_file1) || die ($! . " ". $output_file1); open (H2, ">>" . $output_file2) || die ($! . " ". $output_file2); while (defined (my $line = )) { # xxx Special cases for formatting my ($ip, $size) = ($line =~ /^(.*?)\s.*?\s.*?\s\[.*\] \".*?\" \d+ (\d+)/); if ($ip) { my $found = $pt->match_string ($ip); if ($found) { print H1 $line; } else { print H2 $line; } } } close (H1); close (H2);