Last active
August 29, 2015 13:58
-
-
Save Dottenpixel/10434496 to your computer and use it in GitHub Desktop.
Reboot server if connection lost (credit to http://ubuntuforums.org/archive/index.php/t-1889951.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTS="router" | |
COUNT=4 | |
for myHost in $HOSTS | |
do | |
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') | |
echo "Ping count of $count to $myHost at $(date)" >> ~/log/monitor.log | |
if [[ $count == '' ]]; then | |
echo "Host : connection is down (ping failed) at $(date)" >> ~/log/monitor.log | |
reboot | |
fi | |
if [ $count -ne 4 ]; then | |
# partial fail | |
echo "Host : $myHost is only partially connectable (ping failed) at $(date)" >> ~/log/monitor.log | |
reboot | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment