Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3393340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:21+00:00 2026-05-18T04:02:21+00:00

Ok guys I’m really at a dead end here, don’t know what else to

  • 0

Ok guys I’m really at a dead end here, don’t know what else to try…

I am writing a script for some e-mail statistics, one of the things it needs to do is calculate the complete size of all messages in the maillog, this is what I wrote so far:

egrep ' HOSTNAME sendmail\[.*.from=.*., size=' maillog | awk '{print $8}' |  
tr "," "+" | tr -cd '[:digit:][=+=]' | sed 's/^/(/;s/+$/)\/1048576/' |  
bc -ql | awk -F "." '{print $1}'

And here is a sample line from my maillog:

Nov 15 09:08:48 HOSTNAME sendmail[3226]: oAF88gWb003226:  
from=<name.lastname@domain.com>, size=40992, class=0, nrcpts=24,  
msgid=<E08A679A54DA4913B25ADC48CC31DD7F@domain.com>, proto=ESMTP,  
daemon=MTA1, relay=[1.1.1.1]

So I’ll try to explain it step by step:

First I grep through the file to find all the lines containing the actual “size”, next i print the 8th field, in this case “size=40992,”.

Next I replace all the comma characters with a plus sign.

Then I delete everything except the digits and the plus sign.

Then I replace the beginning of the line with a “(“, and I replace the last extra plus sign with a “)” followed by “/1048576”. So i get a huge expression looking like this:

“(1+2+3+4+5…+n)/1048576”

Because I want to add up all the individual message sizes and divide it so I get the result in MB.

The last awk command is when I get a decimal number I really don’t care for precision so i just print the part before the decimal point.

The problem is, this doesn’t work… And I could swear it was working at one point, could it be my expression is too long for bc to handle?

Thanks if you took the time to read through 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:02:21+00:00Added an answer on May 18, 2026 at 4:02 am

    I think a one-line awk script will work too. It matches any line that your egrep pattern matches, then for those lines it splits the eighth record by the = sign and adds the second part (the number) to the SUM variable. When it sees the END of the file it prints out the value of SUM/1048576 (or the byte count in Mibibytes).

    awk '/ HOSTNAME sendmail\[.*.from=.*., size=/{ split($8,a,"=") ; SUM += a[2] } END { print SUM/1048576 }' maillog
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys anyone know what the helll is going on here? ERROR SNIPPET: Loading
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Ok guys just a small game: I have some specifications for a project. At
Ok guys and gals, here is my problem: I've built a custom control that
You guys were very helpful yesterday. I am still a bit confused here though.
guys! I have problem with my .net application. When I try to print in
Guys, I am not exactly sure what happens here for the if statement. I
Guys!! I'm really enthusiastic in learning django and learnt a bit on Django-1.2 but
Guys, i have a little issue here. Im doing a search to my UITableView.
guys. I tried this code: def trap_check(payroll[][], timelive[][]) . . . end I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.