执行 ping 测试以更改 dns

执行 ping 测试以更改 dns

我编写这个脚本是为了检查我的 dns 服务器是否正常工作,如果不正常则更改它。但它给出了错误./dns-ping.sh: line 15: ((: 3 < : syntax error: operand expected (error token is "< ")

哪里有问题?

#! /bin/bash

loss_count=0
echo "--------------------------------------------------------------"
echo "++ DNS Ping Tester ++"
echo "--------------------------------------------------------------"
echo "please enter threshold:"
read $threshold
for timer in {1..2}
    do
        png=`ping -c 5 -q yahoo.com | grep -oP '\d+(?=% packet loss)'`
        let loss_count=$png+$loss_count
done
let loss_mid=loss_count/12
if (($loss_mid < $threshold)); then
#   ifdown eth0
    echo "less"
else
    echo "nameserver 8.8.8.8" > /etc/resolv.conf
fi

答案1

您必须替换以下行:

if (($loss_mid < $threshold)); then

通过这个:

if [ "$loss_mid" -lt "$threshold" ]; then

相关内容