Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* 簡易アクセス集計スクリプト(携帯) [#o00f3515]
携帯端末からのアクセスを集計する。
** 使い方 [#j6e8133a]
シェルからApacgeのアクセスログファイルを引数にして実行。...
./this-script.pl /var/www/logs/access_log.200908* > 2009...
** スクリプト [#g41a38b1]
#!/usr/local/bin/perl
use strict;
use warnings;
use DateTime::Format::HTTP;
use Data::Dumper;
my %agent = (
'SB' => [ 'J-PHONE', 'Vodafone', 'SoftBank', 'MO...
'DOCOMO' => [ 'DoCoMo' ],
'AU' => [ 'KDDI-', 'UP\.Browser', ],
);
my @files = @ARGV;
my %data;
foreach my $file (@files) {
open my $fh, '<', $file or die "$!: $file";
while ( my $line = <$fh> ) {
chomp $line;
my ( $host, $ident, $user, $time, $request, $sta...
( $line =~ /^([^ ]*) ([^ ]*) ([^ ]*) \[([^]]*)...
my $dt = DateTime::Format::HTTP->parse_datetime(...
next unless $request =~ m#^(GET|POST) /index.htm...
unless ( exists $data{ $dt->ymd } ) {
$data{ $dt->ymd }->{$_} = 0 for qw/SB DOCOMO...
}
my $hit;
if ( grep { $agent =~ /^$_/ } @{ $agent{SB} } ) {
$data{ $dt->ymd }->{SB} = $data{ $dt->ymd }-...
$hit = 1;
}
elsif ( grep { $agent =~ /^$_/ } @{ $agent{DOCOM...
$data{ $dt->ymd }->{DOCOMO} = $data{ $dt->ym...
$hit = 1;
}
elsif ( grep { $agent =~ /^$_/ } @{ $agent{AU} }...
$data{ $dt->ymd }->{AU} = $data{ $dt->ymd }-...
$hit = 1;
}
if ($hit) {
$data{ $dt->ymd }->{ALL} = $data{ $dt->ymd }...
}
}
close $fh;
}
#print Dumper \%data;
print "date,DOCOMO,AU,SB,ALL\n";
foreach my $ymd ( sort keys %data ) {
printf "%s,%d,%d,%d,%d\n", $ymd, $data{$ymd}->{DOCOM...
}
終了行:
* 簡易アクセス集計スクリプト(携帯) [#o00f3515]
携帯端末からのアクセスを集計する。
** 使い方 [#j6e8133a]
シェルからApacgeのアクセスログファイルを引数にして実行。...
./this-script.pl /var/www/logs/access_log.200908* > 2009...
** スクリプト [#g41a38b1]
#!/usr/local/bin/perl
use strict;
use warnings;
use DateTime::Format::HTTP;
use Data::Dumper;
my %agent = (
'SB' => [ 'J-PHONE', 'Vodafone', 'SoftBank', 'MO...
'DOCOMO' => [ 'DoCoMo' ],
'AU' => [ 'KDDI-', 'UP\.Browser', ],
);
my @files = @ARGV;
my %data;
foreach my $file (@files) {
open my $fh, '<', $file or die "$!: $file";
while ( my $line = <$fh> ) {
chomp $line;
my ( $host, $ident, $user, $time, $request, $sta...
( $line =~ /^([^ ]*) ([^ ]*) ([^ ]*) \[([^]]*)...
my $dt = DateTime::Format::HTTP->parse_datetime(...
next unless $request =~ m#^(GET|POST) /index.htm...
unless ( exists $data{ $dt->ymd } ) {
$data{ $dt->ymd }->{$_} = 0 for qw/SB DOCOMO...
}
my $hit;
if ( grep { $agent =~ /^$_/ } @{ $agent{SB} } ) {
$data{ $dt->ymd }->{SB} = $data{ $dt->ymd }-...
$hit = 1;
}
elsif ( grep { $agent =~ /^$_/ } @{ $agent{DOCOM...
$data{ $dt->ymd }->{DOCOMO} = $data{ $dt->ym...
$hit = 1;
}
elsif ( grep { $agent =~ /^$_/ } @{ $agent{AU} }...
$data{ $dt->ymd }->{AU} = $data{ $dt->ymd }-...
$hit = 1;
}
if ($hit) {
$data{ $dt->ymd }->{ALL} = $data{ $dt->ymd }...
}
}
close $fh;
}
#print Dumper \%data;
print "date,DOCOMO,AU,SB,ALL\n";
foreach my $ymd ( sort keys %data ) {
printf "%s,%d,%d,%d,%d\n", $ymd, $data{$ymd}->{DOCOM...
}
ページ名: