comparison log_analyze.rb @ 0:b42d5cbbd972

add
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 18 Jul 2018 17:25:20 +0900
parents
children 4f7103163762
comparison
equal deleted inserted replaced
-1:000000000000 0:b42d5cbbd972
1 #!/usr/bin/env ruby
2
3 file = "/var/log/system.log"
4
5 user_name = Regexp.new("anatofuzMBP|anatofuz-15")
6 count = Hash.new(0)
7
8 File.open(file,'r') do |f|
9 f.each_line do |line|
10 if line =~ /\w \d{0,2} (?:\d{2}:?){3} #{user_name} ([\w.]+)\[\d+\]/
11 count[$1] += 1
12 end
13 end
14 end
15
16
17 sum = 0
18
19 for key in count.keys
20 sum += count[key]
21 end
22
23 p sum