Skip to content

Instantly share code, notes, and snippets.

@lovemyliwu
Last active January 28, 2023 07:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lovemyliwu/e6cc7c8e9f9edfd15d8311c555b14f92 to your computer and use it in GitHub Desktop.
Save lovemyliwu/e6cc7c8e9f9edfd15d8311c555b14f92 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