#!/bin/bash
#### 要在这个脚本的平级目录新建一个txt文档放域名####
#sj=`date '+%Y-%m-%d-%H-%M'`
#sjj=`date '+%Y-%m-%d-%H-%M-%S'`
sj=`date '+%Y-%m-%d'`
sjj=`date '+%Y-%m-%d'`
shijian=`date '+%Y-%m-%d-%H:%M:%S'`
for ym in `cat  /opt/sh/HuaYang.txt |grep -v "#"`
do
        if [ -n "$ym" ];then
         c1=$(curl -o /dev/null -s -w %{http_code} https://$ym)
        fi
       yuming="当前域名: "$ym
       cc1=%0A"域名状态码为: "$c1
       aaa="需要检查域名"
        if [  $c1 -ne 200 ];then
            curl -X POST "https://api.telegram.org/bot1218465982:AAHjRhPmDMXq4P3p3vHvZfC6PtqYHzrGDX4/sendmessage?chat_id=-1001521979318&text= ""$yuming $cc1 $aaa  "
           else
           echo " 当前域名: $ym  状态码为: $c1 当前时间为: $shijian " >> /opt/sh/log/HuaYangrizhi-"$sj".log
         fi
done
### %0A 是html 里面的换行符 ###
for yuming in  `cat /opt/sh/HuaYang.txt |grep -v "#"`
 do
Ip=`nslookup $yuming  114.114.114.114 |grep -v grep  |grep Address |awk '{print $2}'|sed -n "2,10p"`
IPPP=($Ip)

if [   -z "$Ip"   ]
  then
   curl -X POST "https://api.telegram.org/bot1218465982:AAHjRhPmDMXq4P3p3vHvZfC6PtqYHzrGDX4/sendmessage?chat_id=-1001521979318&text= 当前时间: $sj %0A 当前解域名: $yuming %0A 当前域名解析为空,需要更换"
  else
   for i in ${IPPP[@]}
   do
   echo "当前时间: $sj %0A 当前解域名: $yuming %0A 当前IP: $i 当前时间为: $shijian"  >> /opt/sh/log/rizhi-"$sjj".log
   done
fi
done
sleep 40
