最近在做些打杂的事情,需要对dns做一下健康检查。脚本直接shell写的,以前的同事的方案只是直接检查一下named进程是否存在,存在就是表示OK的,这个策略显然是有问题的,比如进程假死之类的其实是没有办法检查的。然后我就想着改成nslookup或者host命令进行一个查询,检测返回值,由于nslookup的返回值不能体现出查询是否成功,就只有host可以用了。```bash check_dns(){local domainlocal serverdomain=“www.xxx.com"server=’127.0.0.1′
host -W1 $domain $server &>/dev/nullerror=$?if [ $error -ne $STATUS_OK ];thenwarn "can’t resolve $domain,error."fireturn $error}
check_dns(){local domainlocal serverdomain="www.xxx.com"server=’127.0.0.1′dig @$server $domain +time=1 +retry=1 +tries=1 &>/dev/nullerror=$?if [ $error -ne $STATUS_OK ];thenwarn "can’t resolve $domain,error."fireturn $error