From be392b42cd8a0a5e4ea4ca4410636a1e1464a317 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 16 Oct 2021 23:43:52 +0200 Subject: [PATCH] Imported usable scripts from the private temporary repository --- scripts/reset-wifi-if-no-connection.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 scripts/reset-wifi-if-no-connection.sh diff --git a/scripts/reset-wifi-if-no-connection.sh b/scripts/reset-wifi-if-no-connection.sh new file mode 100644 index 0000000..f00f606 --- /dev/null +++ b/scripts/reset-wifi-if-no-connection.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh + +interface="wlan0" + +max_retries=3 +timeout=1 + +log_path="$(dirname $0)/$(basename $0).log" +log_prefix="$(date +'%Y-%m-%d %T')" + +i=0 +until [ $i -eq $max_retries ]; do + let "i++" + if nc -Nz -w $timeout www.google.com 443; then + echo "$log_prefix" "connection is OK" >> $log_path + break + else + echo "$log_prefix" "no connection, resetting interface" >> $log_path + sudo ifconfig wlan0 down && sudo ifconfig wlan0 up + fi +done