Skip to content

Instantly share code, notes, and snippets.

@u007
Created July 14, 2016 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u007/2ed99a674dc10cee77c1e5c9c5ca0b2a to your computer and use it in GitHub Desktop.
Save u007/2ed99a674dc10cee77c1e5c9c5ca0b2a to your computer and use it in GitHub Desktop.
extract email bandwidth usage for a domain grouped by day
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