Created
July 14, 2016 15:58
-
-
Save u007/2ed99a674dc10cee77c1e5c9c5ca0b2a to your computer and use it in GitHub Desktop.
extract email bandwidth usage for a domain grouped by day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd = 'grep @domain.com /var/log/maillog | grep retr= | awk {\'print $6" "$1" "$2" "$3" "$11\'} | grep -v retr=0' | |
output = [] | |
r, io = IO.pipe | |
fork do | |
system(cmd, out: io, err: :out) | |
end | |
io.close | |
list = {} | |
r.each_line{|l| | |
res = l.split(' ') | |
email = res[0].gsub('pop3(','')+'-'+res[1]+res[2] | |
byte = (res[4].split('/').last[0..-2].to_f/1024/1024).round(4) | |
if list.has_key?(email) | |
list[email][:size] +=byte | |
else | |
list[email] = { size: byte } | |
end | |
puts 'key: ' + email + ", size: "+ byte.to_s | |
} | |
puts "result===========" | |
list.keys.each do |key| | |
puts key+": "+list[key][:size].round(4).to_s+"MB" | |
end | |
puts 'done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment