统计黑ip的脚本
#!/bin/bash while [ 1 > 0 ] do cd /var/openresty/nginx/logs
#统计nginx日志,将结果重定向到文件blackip.txt中 cat access.log|grep '"POST /sys/submit_phone_validate_code.do HTTP/1.1" 403'|awk '{print $1}' | sort | uniq -c > blackip.txt echo "write in blackip.txt success!" tatol_txt=`cat blackip.txt |wc -l` #统计黑ip总数 for ((i=1; i <= $tatol_txt;i++)) do tatol_ip=`sed -n ${i}p blackip.txt |awk '{print $1}'` #统计单行中黑ip访问次数 if [ $tatol_ip -gt 10 ] then black_ip=`sed -n ${i}p blackip.txt |awk '{print $2}'`#取出该黑ip redis-cli sadd black.ip $black_ip #加入到redis echo $black_ip echo > access.log fi done sleep 1m done
End!