Skip to content

Instantly share code, notes, and snippets.

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