![执行 ping 测试以更改 dns](https://linux22.com/image/30844/%E6%89%A7%E8%A1%8C%20ping%20%E6%B5%8B%E8%AF%95%E4%BB%A5%E6%9B%B4%E6%94%B9%20dns.png)
我编写这个脚本是为了检查我的 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