Dieses Script ist für Router die selbst Internet anbieten gedacht, wer nur Mesht braucht das eigendlich nicht oder muss es ggf. anpassen.
Hallo, hier eine überarbeitete Version meines Check Scriptes, ich nutze es für meine CPE210. Es überprüft die Anzahl der Wireless Clients (wenn 0 dann reset WIFI), und es überprüft ob Traffic über das VPN geht (wenn nein dann reset WAN > wait > wenn immer noch nicht dann reboot) das script sollte nicht unter 10min ausgeführt werden, da es sonst zu double runs kommen kann. also in crontab mindestens 10 Minuten. Wifi Check und VPN b.z.w. WAN Check kann an oder aus gemacht werden. Ihr müsst nur das richtige Interface eintragen. Bei mir ist es ffuplink. Solltet ihr kein VPN nutzen, dann einfach das WAN Interface eintragen. Viel Spaß.
#!/bin/sh
CHECKWIFI=true;
CHECKINTERNET=true;
wanif="ffuplink";
ws1="freifunk.net";
ws2="8.8.8.8";
ws3="google.de";
ALOSF=false;
ALOSF2=false;
if [ "$CHECKWIFI" = true ]; then
# Check Wireless Interface
NOASSOCS="/tmp/noassocs"
LIMIT="120"
ASSOCS=$(/usr/sbin/iw dev wlan0-dhcp-2 station dump | /bin/grep Station | /usr/bin/wc -l)
if [ $ASSOCS -eq "0" ]; then
if [ -f $NOASSOCS ]; then
let "DELTA=$(/bin/date +%s)-$(/bin/cat $NOASSOCS)"
if [ $DELTA -gt $LIMIT ]; then
# restart wifi
/usr/bin/logger -t wifi-watchdog "restarting wifi"
/sbin/wifi
/bin/rm -f $NOASSOCS
fi
else
/bin/date +%s > $NOASSOCS
fi
else
[ -f $NOASSOCS ] && /bin/rm -f $NOASSOCS
fi
fi
if [ "$CHECKINTERNET" = true ]; then
# Check WAN Interface
ping -I "$wanif" -c 1 "$ws1"
if [ "$?" = 0 ]; then
ALOSF=true;
fi
ping -I "$wanif" -c 1 "$ws2"
if [ "$?" = 0 ]; then
ALOSF=true;
fi
ping -I "$wanif" -c 1 "$ws3"
if [ "$?" = 0 ]; then
ALOSF=true;
fi
if [ "$ALOSF" = false ]; then
# Error 1 Reconnect the WAN Interface
ifup wan
else
exit 0
fi
sleep 1m
ping -I "$wanif" -c 1 "$ws1"
if [ "$?" = 0 ]; then
ALOSF2=true;
fi
ping -I "$wanif" -c 1 "$ws2"
if [ "$?" = 0 ]; then
ALOSF2=true;
fi
ping -I "$wanif" -c 1 "$ws3"
if [ "$?" = 0 ]; then
ALOSF2=true;
fi
if [ "$ALOSF2" = false ]; then
# Error 2 Reboot the Device
reboot
else
exit 0
fi
fi