1 [root@localhost domain]# cat check_domain.sh
2 #!/bin/bash
3 script_dir=`dirname $0`
4
5 a=0
6 for line in `awk -F'[ \t]+' '{print $1"|"$2"|"$3}' /python/saltnew/domain/wdzj_domain.log`
7 do
8 a=`expr $a + 1`
9 host=`echo $line|awk -F'|' '{print $1}'`
10 ip=`echo $line|awk -F'|' '{print $2}'`
11 sign=`echo $line|awk -F'|' '{print $3}'`
12 values=`curl -X GET --connect-timeout 5 -s -I -H "Host:$host" http://"$ip" | awk -v dom="$host $ip" '{if (NR==1 && $2 == "200" || $2 == "301") {print dom": " $1"\033[32m "$2" \033[0m"$3} else if (NR==1 && $2 != "200" && $2 != "301") {print dom": " $1"\033[31m "$2" \033[0m"$3}}'`
13 echo "$values"
14 status=`echo $values | awk '{print $(NF-1)}'`
15
16 if [ "$status" == "200" ] || [ "$status" == "301" ] && [ "$status" != "" ] ;then
17 list_two[$a]="$host $ip $status $sign"
18 fi
19
20 if [ "$status" != "200" ] && [ "$status" != "301" ] && [ "$status" != "" ] ;then
21 list[$a]="$host $ip $status $sign"
22 fi
23 done
24
25 #恢复
26 for i in "${list_two[@]}"
27 do
28 i_host=`echo "$i" | awk '{print $1}'`
29 i_ip=`echo "$i" | awk '{print $2}'`
30 i_values=`echo "$i" | awk '{print $3}'`
31 i_sign=`echo "$i" | awk '{print $4}'`
32 if grep -x "$i_sign" ${script_dir}/sign.txt > /dev/null
33 then
34 echo "已恢复"
35 python ${script_dir}/sendSMS.py "$i_host $i_ip $i_values"
36 sed -i "/$i_sign/d" ${script_dir}/sign.txt
37 fi
38 done
39
40 #报警
41 for ii in "${list[@]}"
42 do
43 ii_host=`echo "$ii" | awk '{print $1}'`
44 ii_ip=`echo "$ii" | awk '{print $2}'`
45 ii_values=`echo "$ii" | awk '{print $3}'`
46 ii_sign=`echo "$ii" | awk '{print $4}'`
47 if ! grep -x "$ii_sign" ${script_dir}/sign.txt > /dev/null
48 then
49 echo "网站报警"
50 python ${script_dir}/sendSMS.py "$ii_host $ii_ip $ii_values"
51 echo "$ii_sign" >> ${script_dir}/sign.txt
52 fi
53 done
1 [root@localhost domain]# cat wdzj_domain.log
2 www.wdzj.com 11.1.1.1 1
3 www.wdzj.com 11.1.1.1/news/ 2
1 [root@localhost domain]# cat sendSMS.py
2 #!/usr/bin/python
3 #-*- coding: utf-8 -*-
4 ###############################################
5 # #
6 # creator: zenghui #
7 # datetime: 07/09/2015 #
8 # #
9 ###############################################
10
11 import time
12 import commands,sys
13 from mustaine.client import HessianProxy
14
15 def sendSMS(phone,content,character,template):
16 print proxy.sendSMS(phone,content,character,template)
17
18 if __name__ == '__main__':
19 mobile_phone='手机号码'
20 times=time.strftime('%Y-%m-%d %H:%M:%S')
21 proxy = HessianProxy('http://ip/sms')
22 #print proxy
23 sendSMS(mobile_phone,sys.argv[1],'huaxin','3')