Script command to read wifi SSID for active connection

I am building a new OSMC box using anb RPi4B device and the latest OSMC installer via Pi-Imager.

My devices report their network data via a call to a reporting function on my website when they boot and have been connected to the Internet.
On all of my other RPi systems I can use this command in the script to retrieve the active SSID:
WiFiSSID=$(iwconfig wlan0 | grep 'ESSID:' | sed -n 's/.*ESSID://p' | tr -d '"')

But on OSMC this does not work because iwconfig is not installed.
This is what I see when I check iwconfig and iw via apt:

$ apt policy iwconfig
N: Unable to locate package iwconfig
$ apt policy iw
  Installed: (none)
  Candidate: 5.9-3
  Version table:
     5.9-3 500
        500 bullseye/main armhf Packages

Googling only brings up other similar commands all using a different function not existing on OSMC. :frowning:


  1. Will installing iw somehow break the MyOSMC handling of wifi?

  2. Is there a way in a script to ask the operating system on OSMC for the currently connected SSID? Without installing some other networking utility.

WiFiSSID=$(iw dev | sed -En 's/.*ssid.(.*)$/\1/p')

I have already tried iw, but it is not installed and I am worried that if I install it I would break the working WiFi handling of OSMC…

$ iw dev | sed -En 's/.*ssid.(.*)$/\1/p'
-bash: iw: command not found

There are other packages not installed as well, which I install if I need them.
But in this case I don’t know if installing iw will break whatever WiFi handler OSMC is using…

I thought that was in a default install since I had that but not iwconfig. It won’t pose an issue. Apparently I’ve had it installed long enough that I had forgot I installed it on my Vero V.

After I installed iw (sudo apt install iw -y) I could do this:

WiFiSSID=$(iw dev | grep -A 7 wlan0 | grep ssid | awk '{print $2}')
WiFiLevel=$(iw dev wlan0 station dump | grep signal: | awk '{print $2}')

And I was suggested by my son-in-law to use ChatGPT instead of Google…
Got a working solution from a simple ask on ChatGPT

No you didn’t. You got an inelegant and easily broken solution when you already were given something that wasn’t…

osmc@VeroV:~$ iw dev | sed -En 's/.*ssid.(.*)$/\1/p'
osmc@VeroV:~$ iw dev | grep -A 7 wlan0 | grep ssid | awk '{print $2}'
1 Like

You could refer your future queries to ChatGPT.


too bad…