Good evening
I would need a script in bash that follows this command:
ping -c 4 -i "IP" for 3 times. Each ping must be performed at a distance of 10 minutes and only when it fails all 3 times, it send an e-mail. Could you help me?
Ex.
ping -c 4 -i X.X.X.X
Execution type: first ping, if all packet loss, wait 10 minutes and execute again ping command, if still failed execute again last ping and if failed, send an e-mail
#!/bin/bash
HOSTS="X.X.X.X"
pingtest(){
for myHost in "$@"
do
ping -c 4 -i 5 $HOSTS && return 1
done
return 0
}
if pingtest $HOSTS
then
# 100% failed
echo "Server failed" | mail -s "Server Down" [email protected]
fi
but how can repeat it 3 times and only after it fails with packet loss, send an email? Thank you