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/11040390 to your computer and use it in GitHub Desktop.
Save alexalouit/11040390 to your computer and use it in GitHub Desktop.
POSTFIX bounced mail regular email report
#!/bin/bash
#
# cron ex: 1 0 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /root/scripts/mail-bounced.sh >> /root/scripts/cron.log
email=""
dir="/tmp/"
file="/var/log/mail.info"
occur="status=bounced"
cd $dir
if [ -f ./script-mail-bounced ]
then
if [ -f ./script-mail-bounced-last ]
then
rm ./script-mail-bounced-last
fi
mv ./script-mail-bounced ./script-mail-bounced-last
touch ./script-mail-bounced
chmod -R 777 ./script-mail-bounced
else
touch ./script-mail-bounced
chmod -R 777 ./script-mail-bounced
fi
grep $occur $file > ./script-mail-bounced
if [ -f ./script-mail-bounced-last ]
then
if diff ./script-mail-bounced ./script-mail-bounced-last >/dev/null ;
then
rm ./script-mail-bounced
else
contain=$(diff ./script-mail-bounced ./script-mail-bounced-last)
echo -e "SMTP report (bounced):\n $contain" | mail -s "SMTP report (bounced)" $email
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment