Skip to content

Instantly share code, notes, and snippets.

@benschweizer
Last active November 19, 2021 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benschweizer/6120e1e59ce67b8dfe218f94fd12908d to your computer and use it in GitHub Desktop.
Save benschweizer/6120e1e59ce67b8dfe218f94fd12908d to your computer and use it in GitHub Desktop.
watchdog checking network interface
#!/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