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
#!/usr/bin/perl -w
use warnings;
use strict;
use Term::ANSIColor;
my $log = "error.log";
my %seen =();
open (my $fh, "<", $log) or die "unable to open $log: $!";
while( my $line = <$fh> ) {
chomp $line;
if( $line =~ /error/ ){
$seen{$line}++;
}
}
close $fh;
for my $key ( keys %seen ) {
if( $line =~ /PHP Fatal error/ ){
print colored("$key:\n","red");
}
}
2013-09-03T12:47:18 pqich nehme an, in zeile 24 wolltest du eher $key als $line benutzen =)
$line deklarierst und benutzt du ja nur in der ersten schleife.
1 2 3 4 5 6
use Date::Parser; my $line = '[26-Oct-2013 13:10:44] irgendwas...'; my $format = "%d-%h-%Y %H:%M:%S"; my $parser = Date::Parser->new; my $epoche = $parser->parse_data( $format, $line )->unixtime;
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
use strict; use warnings; use Time::Local; use 5.010; my %seen; my %months = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6, Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12, ); open my $fh, "<", "phperrors.log" or die $!; my @lines; while (my $line = <$fh>) { chomp $line; if ($line =~ /error/) { unless ($seen{ $line }++) { if ($line =~ m/^\[(\d{2})-(\w{3})-(\d{4}) (\d{2}):(\d{2}):(\d{2})\]/) { my ($day, $monthname, $year, $hour, $minute, $sec) = ($1, $2, $3, $4, $5, $6); my $month = $months{ $monthname } - 1; my $epoch = timelocal($sec, $minute, $hour, $day, $month, $year); push @lines, [$epoch, $line]; } } } } @lines = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @lines; say for @lines;