Mercurial > hg > Members > anatofuz > Perl6_log_analyze_example
diff log_analyze.pl @ 0:b42d5cbbd972
add
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Jul 2018 17:25:20 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/log_analyze.pl Wed Jul 18 17:25:20 2018 +0900 @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +my $file = "/var/log/system.log"; + +if(@ARGV == 2){ + if ( $ARGV[0] eq "-f"){ + $file = $ARGV[1]; + } +} + +my $user_name = qr/anatofuzMBP|anatofuz-15/; +open my $fh, "<",$file; +my $count = {}; + +while (my $line = <$fh>) { + if ( $line =~ /\w \d{0,2} (?:\d{2}:?){3} $user_name ([\w.]+)\[\d+\]/){ + $count->{$1}++; + } +} + +my $sum = 0; + +for my $key (keys %$count){ + $sum += $count->{$key}; +} + +print "$sum\n";