Last active
October 13, 2015 03:46
-
-
Save koy1619/da726d0b83f87220f141 to your computer and use it in GitHub Desktop.
Denyhosts.sh
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 | |
#Denyhosts SHELL SCRIPT | |
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"=" $1;}' >/home/sh/Denyhosts.txt | |
DEFINE="10" | |
for i in `cat /home/sh/Denyhosts.txt` | |
do | |
IP=`echo $i|awk -F= '{print $1}'` | |
NUM=`echo $i|awk -F= '{print $2}'` | |
if [ $NUM -gt $DEFINE ] | |
then | |
grep $IP /etc/hosts.deny >/dev/null | |
if [ $? -gt 0 ]; | |
then | |
echo "sshd:$IP" >> /etc/hosts.deny | |
fi | |
fi | |
done | |
# */1 * * * * sh /home/sh/Denyhosts.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment