需求: IDC机房通报一堆客户接口域名过期掉备案了,需要我这边判断这些域名里那边是客户那边已经暂停解析的,那些是还有解析记录的,然后通知客户暂停域名解析
先排序去除重复的域名:
cat 2.txt |sort -rn|uniq -c|awk '{print $2}' >b.txt
从b.txt 这个文件中查找那些还是有解析记录的:
for n in `cat /root/b.txt`;do echo $n& ping -c1 -i 0.1 $n -q|grep 'PING'|grep -v '127.0.0.1';done;
执行过程中输出的内容如下:
[1] 38765 m.z3o8i.cn [1]+ Done echo $n [1] 38769 m.z1w4ri.cn [1]+ Done echo $n [1] 38773 m.yunranfa.cn PING s.cooolyi.cn (221.195.1.103) 56(84) bytes of data. [1]+ Done echo $n [1] 38835 m.yunnvjie.cn PING s.cooolyi.cn (183.60.136.216) 56(84) bytes of data. [1]+ Done echo $n [1] 38839 m.yqbyiw86.cn PING s.cooolyi.cn (183.60.136.216) 56(84) bytes of data. [1]+ Done echo $n
把上面的输出的内容追加到文件11.txt 文件 过滤出还有解析的,以m开头的二级域名:
sed -e '/Done/{d}' -e '/\[1\]/{d}' 11.txt|grep -B 1 'PING'|grep "^m"
过滤出还有解析的,以.cn结尾和.com 结尾的二级域名:
[root@localhost ~]# sed -e '/Done/{d}' -e '/\[1\]/{d}' 11.txt|grep -B 1 'PING'|grep ".cn$"|head -2 m.yunranfa.cn m.yunnvjie.cn [root@localhost ~]# sed -e '/Done/{d}' -e '/\[1\]/{d}' 11.txt|grep -B 1 'PING'|grep ".com$"|head -2 m.vhu5j1.com m.qeiuke.com