#!/usr/bin/perl -w # # Copyright (c) 2002 Ivan Kohler # All rights reserved. # This program is free software; you can redistribute it and/or modify it under # the same terms as Perl itself. # # ivan-icelog@420.am use strict; use vars qw($eof); #use Date::Parse; use Time::Local; my $c = 0; my %mon = map { ( $_ => $c++ ) } qw( jan feb mar apr may jun jul aug sep oct nov dec ); $|=1; $eof=0; my( $file, $pos ) = @ARGV; open(FILE,"<$file") or die "Can't open $file: $!"; seek(FILE,$pos,0) or die "Can't seek: $!"; $SIG{'HUP'} = sub { print "EOF\n"; exit; }; #$SIG{'HUP'} = sub { $eof=time; }; # set an alarm while (1) { while () { next if /^$/; #rootwood.haze.st - - [24/Dec/2001:15:33:50 -0800] "GET / HTTP/1.0" 200 1388544 "-" "xmms/1.2.5" 89 /^ ([\w\-\.]+)\ #hostname ([\w\-]+)\ #identd!! ([\w\-]+)\ #authname \[(\d{2})\/(\w{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2})\ -(\d{4})\]\ #date "GET\ ([\/\w\-\.]+)\ HTTP\/\d\.\d"\ # request string (\d{3})\ #staus resonse (\d+)\ #bytes "([^"]*)"\ #referer "([^"]*)"\ #user agent (\d+) #seconds connected $/xo or do { die "unparsable line: $_"; next; }; #warn "ok: $_"; my $hostname = $1; my( $mday, $mon, $year, $hours, $min, $sec, $zone ) = ( $4, $5, $6, $7, $8, $9, $10 ); my $mountpoint = $11; my $status = $12; my $bytes = $13; my $referer = $14; my $useragent = $15; my $seconds = $16; $SIG{HUP} = sub { $eof=1 }; print join("\t", tell FILE, hostname => $hostname, start => timelocal($sec, $min, $hours, $mday, $mon{lc($mon)}, $year), mountpoint => $mountpoint, bytes => $bytes, useragent => $useragent, seconds => $seconds, ), "\n"; $SIG{'HUP'} = sub { print "EOF\n"; exit; }; if ( $eof ) { print "EOF\n"; exit; } } sleep 1; seek(FILE,0,1); }