#!/bin/bash
FILES="/data/nginx_log/xxxxx/access.log"
DATE=`date -d '1 minutes ago' +%Y:%H:%M`
grep ${DATE} ${FILES}|awk -F'|' '{print $3}'|sort -n|uniq -c |sort -nr|head -1>/tmp/ips
grep ${DATE} ${FILES}|grep -i passwd|awk -F'|' '{print $3}'|sort -n|uniq>/tmp/ippwd
NUM=`awk '{print $1}' /tmp/ips`
IP=`awk '{print $2}' /tmp/ips`
IP2=`cat /tmp/ippwd`
threshold=1000
if [[ $NUM -gt $threshold ]];then
/sbin/ipset -! add forbidip $IP timeout 3600
fi
if [ -s /tmp/ippwd ];then
for i in $IP2
do
/sbin/ipset -! add forbidip $i
done
fi