-
Notifications
You must be signed in to change notification settings - Fork 4
/
access_log2epstat
executable file
·51 lines (45 loc) · 1.16 KB
/
access_log2epstat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env perl
#====================================================================
# access_log2epstat
# File ID: af31d840-5d36-11df-aa67-90e6ba3022ac
# Konverterer access_log fra Apache til fil som passer til epstat(1).
# Langt og trasig navn, men nøye då.
#====================================================================
use strict;
use warnings;
use Time::Local;
# 194.248.216.3 - - [13/Aug/2001:16:04:37 +0200] "GET
my %mnd_hash = (
'Jan'=>0, 'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4, 'Jun'=>5,
'Jul'=>6, 'Aug'=>7, 'Sep'=>8, 'Oct'=>9, 'Nov'=>10, 'Dec'=>11
);
while (<>) {
if (m!
\S+ # IP
\s+
\S+
\s+
\S+
\s+
\[
(\d+) # Dato
/
(\S+) # Mnd
/
(\d{4}) # År
:(\d\d):(\d\d):(\d\d) # Klokka
\s+
([+\-]\d\d)(\d\d)
!x
) {
my ($Day, $Mon, $Year, $Hour, $Min, $Sec, $zone_hour, $zone_min) =
( $1, $2, $3, $4, $5, $6, $7, $8);
my $num_mon = $mnd_hash{$Mon};
my $Secs = timegm($Sec, $Min, $Hour, $Day, $num_mon, $Year);
$Secs -= ($zone_hour*3600); # Vi driter i minuttene fir å få opp farta.
print("$Secs\n");
} else {
print(STDERR "Ukjent linje $.\n");
}
}
__END__