I'm writing bash script that configure network access for my Linux devices.
The script has to be used by not Linux skilled people that has no administrative rights on the device. I wrote the ethernet interfaces configuration part and it's ok. Now I need write Wifi configuration part.
The end of the game is to write configuration inside a netplan configuration yaml file
.
Here the expected workflow of the script:
- manage interactive menu system retrieving Hi-level Wifi parameter (SSID, password, authentication mode, dhcp or manual configuration...)
- Check the Connectivity to the selected Access point
- Save data to netplan configuration yaml file
- Apply changes
Point 1, 3 and 4
are ok... also retrieving the list of the available access point is ok.
What I cannot achieve is the point 2
(Check the Connectivity to the selected Access point). I would like to have an use experience like the next
WIFI configuration parameters:
SSID: My Network
PSK: password
Actions:
- e: Edit
- t: Test connectivity
- s: Save
- q: Quit
Select Action: t
....wait while testing connectivity
Test result: OK
Press a key to continue...
I tried with iwconfig
but it's not working with WPA so it does not apply to the most cases.
I tried wpa_supplicant
and I can do the test but not in the way I'm thinking... It's a foreground test that can be stopped only with ctrl-C
and is hard to read for dummies (my final user taget).
I would like to
- launch the Wifi connection in background
- test in background if the connection to Access Point is ok or not
- close the Wifi connection in back ground (the final goal is to configure netplan)
- Return an OK/Fail response to calling script
Of course it is possible to run wpa_supplicant
connection in bg
but: how to check connectivity and stop it always in bg
?
Any suggestion?
Thanks Sandro
sudo iwconfig wlp4s0 essid MYWIFI key s:ABCDE12345
i get the next response:Error for wireless request "Set Encode" (8B2A) : SET failed on device wlp4s0 ; Invalid argument.
Googling it looks like issue with iwconfig and wpa network – Sandro Varoli Sep 19 '22 at 16:07iwconfig
to initially connect. Please clarify. – chili555 Sep 19 '22 at 18:11nmcli
. Possibly helpful: https://askubuntu.com/questions/1164074/how-to-connect-to-wifi-using-just-the-terminal/1164095#1164095 – chili555 Sep 19 '22 at 23:25iwconfig | grep ESSID
Either the answer is the SSID to which you are connected, or, if not connected, off/any. – chili555 Sep 19 '22 at 23:28Do you think that Network Manager can help with this? – Sandro Varoli Sep 20 '22 at 07:44