Skip to content

Instantly share code, notes, and snippets.

@airtonzanon
Last active October 26, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airtonzanon/cda1e7c4d0f0ae04ccb3759fb7264c28 to your computer and use it in GitHub Desktop.
Save airtonzanon/cda1e7c4d0f0ae04ccb3759fb7264c28 to your computer and use it in GitHub Desktop.
E-mail log para verificar a fila do exim (emails que estão por mais de 12 horas nela)
#!/bin/bash
# info: Send email log to email
# options: NONE
#
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
subject="Log Diário - Fila E-mail"
from="naoresponder@dominio.com.br"
to="webmaster@dominio.com.br"
dir="/tmp/logfila"
dest="$dir/dest.txt"
log="$dir/log.txt"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -d "$dir" ]; then
rm -rf "$dir"
fi
mkdir "$dir"
exiqgrep -i -o 43200 | xargs -I{} exigrep {} /var/log/exim4/mainlog >> "$log"
echo "E-MAILS QUE ESTÃO NA FILA POR MAIS DE 12 HORAS - VERIFICAR" >> "$dest"
echo "" >> "$dest"
echo "E-mails envolvidos:" >> "$dest"
echo "" >> "$dest"
grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" "$dir/log.txt" | sort | uniq | while read -r line ; do
echo "$line" >> "$dest"
done
echo "" >> "$dest"
echo "Lista dos e-mails que estão há mais de 12 horas na fila:" >> "$dest"
exiqgrep -b -o 43200 >> "$dest"
echo "" >> "$dest"
echo "" >> "$dest"
echo "TALVEZ ISTO MEREÇA ATENÇÃO! VERIFIQUE O LOG ANEXO!" >> "$dest"
echo "" >> "$dest"
echo "" >> "$dest"
dataHora=$(date)
echo "Quantidade de e-mails na fila (total) as $dataHora:" >> "$dest"
exim -bpc >> "$dest"
/usr/bin/mail -r $from -a "$log" -s "$subject" $to < "$dest"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment