Skip to content

Instantly share code, notes, and snippets.

@timendum
Last active September 10, 2026 15:52
Show Gist options
  • Select an option

  • Save timendum/4ee359272f6d2d305ca7bbfe7e1fa07a to your computer and use it in GitHub Desktop.

Select an option

Save timendum/4ee359272f6d2d305ca7bbfe7e1fa07a to your computer and use it in GitHub Desktop.
wifi-watchdog.sh

Simple Shell script to check WiFi.

Log at: journalctl -t wifi-watchdog

BusyBox 1.36 compatrible

#!/bin/sh
IFACE="wlan0"
# Get default gateway
GW=$(ip route | awk '/^default/ {print $3; exit}')
# No gateway => reset Wi‑Fi
if [ -z "$GW" ]; then
logger -t wifi-watchdog "No gateway found, restarting $IFACE"
ip link set "$IFACE" down
sleep 5
ip link set "$IFACE" up
exit 0
fi
# Gateway unreachable => reset Wi‑Fi
if ! ping -c 3 -W 2 "$GW" >/dev/null 2>&1; then
logger -t wifi-watchdog "Gateway $GW unreachable, restarting $IFACE"
ip link set "$IFACE" down
sleep 5
ip link set "$IFACE" up
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment