#!/bin/bash
mkdir -m 777 /root/jiankong_log
export LANG=en_US.UTF-8
Port=80
ERROR_TEMP=0
ERROR=0
DATE=`date +%Y-%m-%d" "%k:%M`
echo "$DATE from 121.11.121.177 check 80 error:">/root/jiankong_log/YouJianZhengWen.txt //标志从台检测出来的,因为我有2台监控
biaoti=''
echo "">/root/jiankong_log/YouJianFuJian.txt
echo "-------"$DATE"-------" >>/root/jiankong_log/80jianche.log
echo ''>/root/jiankong_log/ip_tmp.txt
echo "-----------"$DATE"---------">>/root/jiankong_log/error_temp.txt
###################
for Domain in `cat /root/sh/80_URL.txt`
do
echo "------------------$Domain--------------------">>/root/jiankong_log/YouJianFuJian.txt
#START###以下是检测域名是否dig为空的代码,根据情况选择是否开启######
# empty_temp=0
#for i in {1..6}
# do
# a=`dig +short $Domain | head -n 1`
# if [ "$a" != "" ]; then
# break;
# else
# empty_temp=`expr $empty_temp "+" 1`
# ping -c 5 $Domain
# sleep 2
# fi
# if [ "$empty_temp" == "6" ];then
# echo "$Domain dig empty" >>/root/jiankong_log/YouJianZhengWen.txt
# echo "$Domain dig empty" >>/root/jiankong_log/YouJianFuJian.txt
# echo "$Domain dig empty" >>/root/jiankong_log/80jianche.log
# ERROR=1
# biaoti="$biaoti"-"$Domain"
# fi
# done
#END###以上是检测域名是否dig为空的代码,根据情况选择是否开启######
####
for IP in `dig +short $Domain`
do
echo "$IP" >>/root/jiankong_log/ip_tmp.txt
echo "$Domain -----> $IP" >>/root/jiankong_log/YouJianFuJian.txt
done
done
######################
cat /root/jiankong_log/ip_tmp.txt |grep -v ^$| sort -r | uniq | grep "\." >/root/jiankong_log/ip.txt
for newip in `cat /root/jiankong_log/ip.txt |grep -v "#"|grep -Ev "com|58.253.70|221.5" `
do
ERROR_TEMP=0
for n in {1..6} //检测次数
do
nmap -sT $newip -p $Port | grep open
if [ "$?" == "0" ];then
break; //检测到80端口有开,马上跳出此次循环。
else
ERROR_TEMP=`expr $ERROR_TEMP "+" 1`
echo "$newip error in ---- $n ----" >>/root/jiankong_log/error_temp.txt
fi
if [ "$ERROR_TEMP" == "6" ];then
ERROR=1
biaoti="$biaoti"-"$Domain"
grep $newip /root/jiankong_log/YouJianFuJian.txt >>/root/jiankong_log/YouJianZhengWen.txt
grep $newip /root/jiankong_log/YouJianFuJian.txt >>/root/jiankong_log/80jianche.log
fi
done
done
if [ "$ERROR" == "1" ];then
cat /root/jiankong_log/YouJianZhengWen.txt | /usr/local/mutt/bin/mutt -s "$biaoti is error" 1516070****@139.com -c 281450202@qq.com -a /root/jiankong_log/YouJianFuJian.txt //这里的邮件发送方式参考我的另一个,或者根据自己的情况去改下。
else
echo "all is nothing" >>/root/jiankong_log/80jianche.log
fi