Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created October 30, 2019 20:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaneclaes/31ff645e303e1a6c9a86fc166216371d to your computer and use it in GitHub Desktop.
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
#!/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