#!/usr/bin/perl # Created by Ben Okopnik on Fri Oct 31 18:39:15 EST 2003 use warnings; unless ( open Out, ">>$ENV{HOME}/running_log" ){ system qq{echo "`date`: Unable to open running_log; script failed." >> ~/running_log}; exit; } $old = select Out; unless ( open Log, "/var/www/linuxgazette.net-config/logs/access_log" ){ print localtime() . ": Couldn't open access_log: $!\n"; exit 1; } ( $month, $year ) = ( split / /, localtime )[1, 5]; $count = 0; while ( ){ @values = split /[\/\[\]: ]/; if ( (defined $month && defined $year ) && ( $values[5] eq $month ) && ( $values[6] eq $year ) ){ # Hits per IP $hits{ $values[0] }++; # Hits per day $hpd{ $values[4] }++; $count++; } } close Log; print "*********************\nSnapshot taken on " . localtime() . "\n"; printf "$month %s: %d\n", $_, $hpd{ $_ } for sort { $a <=> $b } keys %hpd; $hits = scalar keys %hits; print "$hits unique host${[s=>]}[$hits==1]\n"; print "$count total hit${[s=>]}[$count==1]\n"; select $old;