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 |