需求:
IDC機房通報一堆客戶接口域名過時掉備案了,須要我這邊判斷這些域名裏那邊是客戶那邊已經暫停解析的,那些是還有解析記錄的,而後通知客戶暫停域名解析ide
先排序去除重複的域名:code
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 結尾的二級域名:it
[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