सामग्री पर जाएँ
Email Servers

Daily Postfix Mail Reports with pflogsumm

sudo apt install pflogsumm, then pflogsumm -d yesterday /var/log/mail.log --problems-first. Schedule it with cron and pipe to mail.

परखा गया Ubuntu 22.04 LTS, Postfix 3.6, pflogsumm 1.1.5

pflogsumm reads Postfix logs and produces a short report: messages received and delivered, bounces, deferrals, rejections, top senders and recipients, and server warnings. It’s the quickest way to spot a spam run, a blacklisting or a misconfiguration before users notice.

Install

Terminal
sudo apt install pflogsumm

Generate a report

Terminal
# Today so farnsudo pflogsumm -d today /var/log/mail.lognn# Yesterday (complete day)nsudo pflogsumm -d yesterday /var/log/mail.lognn# Everything in the current log filensudo pflogsumm /var/log/mail.log

The options worth knowing

OptionWhat it does
--problems-firstPuts bounces, deferrals, rejections and warnings at the top
--rej-add-fromAdds the sender address to each rejection line
--verbose-msg-detailShows the full reason instead of a truncated one
-qQuiet – skips headings for empty sections
-u 10 / -h 10Limits the top-users and top-hosts lists
--smtpd-statsAdds connection statistics
A useful daily report
sudo pflogsumm -d yesterday /var/log/mail.log u002du002dproblems-first u002du002drej-add-from u002du002dverbose-msg-detail -q

Email the report every morning

Open root’s crontab:

Terminal
sudo crontab -e

Add these lines – the report for the previous day arrives at 02:00:

crontab
MAILTO=u0022postmaster@example.comu0022n0 2 * * * /usr/sbin/pflogsumm -d yesterday /var/log/mail.log u002du002dproblems-first u002du002drej-add-from u002du002dverbose-msg-detail -q

To send to a different address with a clear subject, pipe the output to mail (from the mailutils package):

crontab
0 2 * * * /usr/sbin/pflogsumm -d yesterday /var/log/mail.log u002du002dproblems-first -q | mail -s u0022Postfix report $(hostname)u0022 you@example.com

Log rotation

Ubuntu rotates mail.log daily. If the 02:00 report misses entries, run it shortly before rotation or point it at both files: /var/log/mail.log.1 /var/log/mail.log. Build other schedules with the Crontab Generator.

Full option list: man pflogsumm.

Inder Kochar

लेखक

Inder Kochar

सिस्टम्स और नेटवर्क इंजीनियर – मैं वही समाधान लिखता हूँ जो क्लाइंट्स के साथ इस्तेमाल करता हूँ, असली सिस्टम पर परखे हुए। ऐसी ही किसी समस्या में फँसे हैं?

आगे पढ़ें

सवाल पूछें या अपना समाधान बताएँ

आपका ईमेल प्रकाशित नहीं होगा। टिप्पणियाँ जाँची जाती हैं – कृपया विषय से जुड़ी रखें।