Skip to content

Instantly share code, notes, and snippets.

@alexalouit
Last active February 19, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexalouit/11040320 to your computer and use it in GitHub Desktop.
Save alexalouit/11040320 to your computer and use it in GitHub Desktop.
POSTFIX blocked mails regular email report
#!/bin/bash
#
# cron ex: 1 0 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /root/scripts/mail-blocked.sh >> /root/scripts/cron.log
email=""
dir="/tmp/"
file="/var/log/mail.info"
occur="Blocked"
cd $dir
if [ -f ./script-mail-blocked ]
then
if [ -f ./script-mail-blocked-last ]
then
rm ./script-mail-blocked-last
fi
mv ./script-mail-blocked ./script-mail-blocked-last
touch ./script-mail-blocked
chmod -R 777 ./script-mail-blocked
else
touch ./script-mail-blocked
chmod -R 777 ./script-mail-blocked
fi
grep $occur $file > ./script-mail-blocked
if [ -f ./script-mail-blocked-last ]
then
if diff ./script-mail-blocked ./script-mail-blocked-last >/dev/null ;
then
rm ./script-mail-blocked
else
contain=$(diff ./script-mail-blocked ./script-mail-blocked-last)
echo -e "SMTP report (blocked):\n $contain" | mail -s "SMTP report (blocked)" $email
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment