Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 - enter image description here

share|improve this question
add comment

4 Answers 4

up vote 1 down vote accepted

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

or

nmcli dev wifi|grep yes| cut -d\' -f2
share|improve this answer
    
it's returning all the connected networks. Can I find only the connected network? –  Chan Apr 18 '13 at 6:45
    
Try it like this and let me know: nmcli -t -f active,ssid dev wifi| cut -d\' -f2 –  Luis Alvarado Apr 18 '13 at 6:46
    
Still returning many results –  Chan Apr 18 '13 at 6:47
    
Can you pastebin what you are seeing as output? –  Luis Alvarado Apr 18 '13 at 6:48
add comment

How 'bout iwconfig wlan0 | sed -e '/ESSID/!d' -e 's/.*ESSID:"/"/'?

share|improve this answer
add comment

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
share|improve this answer
add comment
iwgetid -r

or

iwgetid wlan0 -r
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.