Last active
February 19, 2018 10:22
-
-
Save alexalouit/11040390 to your computer and use it in GitHub Desktop.
POSTFIX bounced mail regular email report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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