Skip to content

Instantly share code, notes, and snippets.

@sean-kang
Created May 1, 2015 01:27
Show Gist options
  • Save sean-kang/d1b34d0e3df57d152435 to your computer and use it in GitHub Desktop.
Save sean-kang/d1b34d0e3df57d152435 to your computer and use it in GitHub Desktop.
Outgoing spam alert cron script
#!/usr/bin/env bash
HOURLY_THRESHOLD=200
total=$(cat /var/log/mail.log | sma -q -d -D 00,59 2>&1 | grep Total | head -1 | awk '{print $4}')
[ -z $total ] && total=0
if [ $total -gt $HOURLY_THRESHOLD ]; then
hostname=$(hostname -f)
cat /var/log/mail.log | sma -q -d -D 00,59 2>&1 | grep -i -A13 'top envelope senders' | mutt -e "set content_type=text/plain" -s "More than ${HOURLY_THRESHOLD} hourly outgoing mails in ${hostname}" me@example.com 2>&1 > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment