#!/bin/bash # Surveille la connexion WiFi et la rétablit si elle tombe. # Conçu pour Surface Pro (wlan0) — lancé par cron ou systemd timer. IFACE="wlan0" GATEWAY=$(ip route show default dev "$IFACE" 2>/dev/null | awk '{print $3}' | head -1) LOG_TAG="wifi-watchdog" if [ -z "$GATEWAY" ]; then logger -t "$LOG_TAG" "Pas de gateway sur $IFACE, tentative reconnexion..." nmcli device connect "$IFACE" 2>&1 | logger -t "$LOG_TAG" sleep 5 GATEWAY=$(ip route show default dev "$IFACE" 2>/dev/null | awk '{print $3}' | head -1) fi if [ -n "$GATEWAY" ]; then if ! ping -c 2 -W 3 -I "$IFACE" "$GATEWAY" > /dev/null 2>&1; then logger -t "$LOG_TAG" "Ping gateway $GATEWAY echoue, reconnexion WiFi..." nmcli device disconnect "$IFACE" 2>&1 | logger -t "$LOG_TAG" sleep 2 nmcli device connect "$IFACE" 2>&1 | logger -t "$LOG_TAG" sleep 5 if ! ping -c 2 -W 3 -I "$IFACE" "$GATEWAY" > /dev/null 2>&1; then logger -t "$LOG_TAG" "Toujours pas de connexion, restart NetworkManager..." systemctl restart NetworkManager fi fi fi