Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.