探测程序本身是 nslookup 命令的 while 死循环。在进行 while 循环之前,将设置一个临时文件,以保留 nslookup 应答。probefail 和 retries 变量初始化为 0。
# Set up a temporary file for the nslookup replies. DNSPROBEFILE=/tmp/.$RESOURCE_NAME.probe probefail=0 retries=0 |
设置探测程序的休眠间隔
使用 hatimerun 启动 nslookup,传送 Probe_timeout 的值并标识目标主机
根据 nslookup 返回代码的成功或失败状态,设置 probefail 变量
如果 probefail 被设置为 1(失败),则核实对 nslookup 的应答是来自数据服务样例而不是其他 DNS 服务器
下面是 while 循环代码。
while :
do
# The interval at which the probe needs to run is specified in the
# property THOROUGH_PROBE_INTERVAL. Therefore, set the probe to sleep
# for a duration of THOROUGH_PROBE_INTERVAL.
sleep $PROBE_INTERVAL
# Run an nslookup command of the IP address on which DNS is serving.
hatimerun -t $PROBE_TIMEOUT /usr/sbin/nslookup $DNS_HOST $DNS_HOST \
> $DNSPROBEFILE 2>&1
retcode=$?
if [ $retcode -ne 0 ]; then
probefail=1
fi
# Make sure that the reply to nslookup comes from the HA-DNS
# server and not from another nameserver mentioned in the
# /etc/resolv.conf file.
if [ $probefail -eq 0 ]; then
# Get the name of the server that replied to the nslookup query.
SERVER=` awk ' $1=="Server:" { print $2 }' \
$DNSPROBEFILE | awk -F. ' { print $1 } ' `
if [ -z "$SERVER" ]; then
probefail=1
else
if [ $SERVER != $DNS_HOST ]; then
probefail=1
fi
fi
fi
|