0

I have been working on scripts to help me administer email servers.

This works pretty well on Postix/Debian server to search logs for sent emails. You can even use grep to search the reasults ie. /root/bin/search-sent-emails.sh |grep domain-name.

log='/var/log/mail.log'
grep "status=sent" $log | \
egrep -ve 'postfix/(cleanup|pickup|master|qmgr|smtpd|local|pipe)'  | cut -f1 -d"(" |sed 's/relay=.*//' |sed 's/delay=.*//' |sed 's/delays=.*//' |sed 's/dsn=.*//'

It could use some fine tuning. How do I add zcat to search older log files like /var/log/mail.log.2.gz etc.

SamTzu
  • 33
  • 6
  • zgrep command works on both compressed and uncompressed files so basically you can change "grep" to "zgrep" in your script and use wildcard to match all mail.log files including the uncompressed one like this: log='/var/log/mail.log*' – FatRabbit Jun 13 '22 at 13:01
  • Great tip. Thx. – SamTzu Jun 13 '22 at 13:08

0 Answers0