How to get the connected wifi network ssid?
I want to obtain the currently connected wifi networks ssid in a bash script. I am trying to write a backup script where the script will perform a backup to a NAS server if it's connected to my home wifi network. I have looked into the ip route
command but it only returns some basic information -
Solution 1:
iwgetid -r
or
iwgetid wlan0 -r
Solution 2:
The following should provide what you are looking for assuming you are connected using 1 wireless device:
nmcli -t -f ssid dev wifi| cut -d\' -f2
Solution 3:
This command returns the SSID of the connected wireless adapter (assuming you only have one).
iwconfig | grep ESSID | sed -e 's/.*ESSID:"\(.*\)".*/\1/'
It also print warning on the terminal but on stderr so it doesn't matter
remi@host~$id:~$ id=$(iwconfig | grep ESSID | sed -e 's/.*ESSID:"\(.*\)".*/\1/')
eth0 no wireless extensions.
lo no wireless extensions.
virbr0 no wireless extensions.
tap0 no wireless extensions.
remi@host:~$ echo $id
CISPI