Last active
January 28, 2023 07:51
-
-
Save lovemyliwu/e6cc7c8e9f9edfd15d8311c555b14f92 to your computer and use it in GitHub Desktop.
auto reconnect wifi after kick out by router on ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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