我需要帮助更新这个脚本,如果 ping 失败,它会向另一个主机发送另一个 ping(除了现在发送的电子邮件,如果 ping 失败)。如何从这个脚本中做到这一点?
#!/bin/bash
HOSTS="IP ADRESS"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | a$
if [ $count -eq 0 ]; then
# 100% failed
echo "Server failed at $(date)" | mail -s "Server Down" myadress@gmail.com
echo "Host : $myHost is down (ping failed) at $(date)"
fi
done
Run Code Online (Sandbox Code Playgroud)