Created
October 30, 2019 20:55
-
-
Save zaneclaes/31ff645e303e1a6c9a86fc166216371d to your computer and use it in GitHub Desktop.
Bash script to automatically connect to open WiFi networks, upon disconnect, via nmcli
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 | |
con="${1}" | |
if [[ -z "$con" ]]; then | |
echo "Please provide an interface name as an argument." | |
exit 1 | |
fi | |
while true; do | |
conns=$(nmcli con show "$con" | grep "GENERAL.STATE:" | grep "activated") | |
if [[ -z "$conns" ]]; then | |
echo "$con is not active; scanning...." | |
nmcli device wifi rescan | |
# nmcli device wifi list | |
nmcli -f SSID dev wifi | |
nmcli device wifi connect SSID-Name # password wireless-password | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment