Skip to content

Instantly share code, notes, and snippets.

@cedricbonhomme
Created January 23, 2014 09:37
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 cedricbonhomme/8575675 to your computer and use it in GitHub Desktop.
Save cedricbonhomme/8575675 to your computer and use it in GitHub Desktop.
Mail IP banned by fail2ban.
#! /bin/sh
servername="Server"
for ip in echo `grep -i unban /var/log/fail2ban.log | awk '{print $NF}' | tail -n 10`
do
for email in `whois $ip | perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}' | sort | uniq`
do
echo "Sending email to $email..."
echo "Hi,
The IP $ip has just been banned by Fail2Ban.
Here are more information about $ip:
`whois $ip`
Regards," | mail -s "$servername banned $ip" $email;
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment