Last active
November 19, 2021 16:25
-
-
Save benschweizer/6120e1e59ce67b8dfe218f94fd12908d to your computer and use it in GitHub Desktop.
watchdog checking network interface
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 | |
# | |
# watchdog checking network interface | |
if [ $# -ne 1 ]; then | |
cat <<HERE | |
usage: | |
ifwatch eth0 | |
HERE | |
exit 1 | |
fi | |
interface=$1 | |
let err_count=0 | |
while true; do | |
while true; do | |
ip address list "$interface" | grep "inet " > /dev/null | |
result=$? | |
if [ $result -ne 0 ]; then | |
logger -s -p crit -t ifwatch "no inet found, err_count=$err_count" | |
err_count=$(($err_count+1)) | |
else | |
err_count=0 | |
fi | |
if [ $err_count -gt 3 ]; then | |
logger -s -p crit -t ifwatch "no inet found, err_count=$err_count, rebooting" | |
reboot | |
fi | |
sleep 60 | |
done | |
done | |
# eof. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment