Skip to content

Instantly share code, notes, and snippets.

@lcuevastodoit
Forked from lovemyliwu/wifi_watch_dog.sh
Created November 4, 2021 19:26
Show Gist options
  • Save lcuevastodoit/d78d95c104dc8052825031ecbe9c4dfe to your computer and use it in GitHub Desktop.
Save lcuevastodoit/d78d95c104dc8052825031ecbe9c4dfe to your computer and use it in GitHub Desktop.
auto reconnect wifi after kick out by router on ubuntu
#!/bin/bash
check_internet_connection() {
return $(ping -c 1 www.baidu.com > /dev/null)
}
SSID=$1
PW=$2
while [ 1 ]; do
check_internet_connection
# already have internet connection
if [ $? -eq 0 ]; then
sleep 10
else
echo "$(date +%Y-%m-%d\ %H:%M:%S) lost internet connection, auto reconnect..."
nmcli conn show --active
nmcli con down $(nmcli conn show --active|grep wifi|awk '{print $(NF-2)}')
nmcli device wifi connect $SSID password $PW
nmcli conn show --active
sleep 5
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment