Last active
October 20, 2020 16:58
-
-
Save SudarshanSMD/d738e3c906243bd3f01aa169cc0bdc16 to your computer and use it in GitHub Desktop.
Gist to switch wifi if one of it goes down
This file contains hidden or 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 | |
# set the profile name/ ssid of your wifi for a and b | |
# a preferably be the SSID/profile that you are already connected | |
# tip: to check the wifi profile you can use command "netsh wlan show profiles" | |
declare a="SMD" | |
declare b="pinjar" | |
declare c=$b | |
echo "scrip started" | |
# infinite loop | |
while true | |
do | |
status=connected | |
while [ "$status" == "connected" ] ; do | |
ping google.com # ping. Optimizes would be -c1 try once, however can only be done in admin mode. | |
rc=$? | |
#echo "$rc" | |
if [[ $rc -ne 0 ]] ; then | |
#echo "disconnected" | |
status="disconnected" # If okay, flag to exit loop. | |
fi | |
sleep 10 | |
#echo "sleeping 10" | |
done | |
echo "ping failed!" | |
echo "disconnecting wlan" | |
netsh wlan disconnect | |
echo "conneting to: $c" | |
netsh wlan connect name=$c | |
#swap the profile name to be used | |
if [ "$c" == "$a" ]; then | |
c=$b | |
else | |
c=$a | |
fi | |
#giving some time to establish connection | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment