很分明,如许是取不到vsftpd失利的IP值的,sshd日记失利信息跟vsftpd日记失利信息纷歧样,我写了几种awk夹杂sed的***,测试了效力,感到用awk剧本速率是最快的,人人也能够写几种,用time下令测试下;最初精简了下代码,完成了全部剧本,剧本内容以下所示:
#!/bin/bash
awk{for(i=1;i<=NF;i++){if($i~/rhost/)printsubstr($i,7)}}/var/log/secure|sort|uniq-c>/root/black.txt
DEFINE="100"
cat/root/black.txt|whilereadLINE
do
NUM=`echo$LINE|awk{print$1}`
host=`echo$LINE|awk{print$2}`
if[$NUM-gt$DEFINE];
then
grep$host/etc/hosts.deny>/dev/null
if[$?-gt0];
then
echo"sshd:$host">>/etc/hosts.deny
echo"vsftpd:$host">>/etc/hosts.deny
fi
fi
done