前段时间一域名解析到一个非自己的IP,后来找DNS供应商才修复。为了往后类似事件再次发生能及时发现特意写了一个简单的脚本添加在nagios上监控。脚本内容如下:
#!/bin/bash CURRENT_IPs=`nslookup www.abcabc.com 8.8.8.8 | grep -v "8.8.8.8" | grep "Address" |awk '{ print $2 }'` MY_IPs=(10.10.22.22 10.10.22.23) for a in ${CURRENT_IPs[@]};do for b in ${MY_IPs[@]};do if [ "$a" != "$b" ];then result="wrong" else result="right" break 1 fi done if [ "$result" = "right" ];then lastresult="OK: Domain www.abcabc.com resolve is normal." else lastresult="CRITICAL: Domain www.abcabc.com resolve is not normal,pls check." break 1 fi done echo $lastresult