0

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:

  1. manage interactive menu system retrieving Hi-level Wifi parameter (SSID, password, authentication mode, dhcp or manual configuration...)
  2. Check the Connectivity to the selected Access point
  3. Save data to netplan configuration yaml file
  4. 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

  1. launch the Wifi connection in background
  2. test in background if the connection to Access Point is ok or not
  3. close the Wifi connection in back ground (the final goal is to configure netplan)
  4. 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

  • 1
    "tried with iwconfig but it's not working with WPA " It certainly does work with WPA/WPA2 and even WPA3. Please clarify. Welcome to Ask Ubuntu. – chili555 Sep 19 '22 at 13:34
  • when I try something like 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:07
  • Your question says you want to just check connectivity. Your comment here suggests that you want to use iwconfig to initially connect. Please clarify. – chili555 Sep 19 '22 at 18:11
  • I was thinking to temporary setup the connection in order to see if credentials are correct and connection can be done. Is there a better way to test connectivity? – Sandro Varoli Sep 19 '22 at 21:53
  • If you want to change networks on a server, very unusual, I suggest Network Manager and specifically nmcli. Possibly helpful: https://askubuntu.com/questions/1164074/how-to-connect-to-wifi-using-just-the-terminal/1164095#1164095 – chili555 Sep 19 '22 at 23:25
  • You can simply test connectivity with iwconfig | 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:28
  • @chili555 Thanks for your suggestion, but this is not what I'm asking. I know how to get ESSID list and how to test if the network is connected... I'm asking how to connect, make a test and disconnect in background so that my dummy user can only wait a response: yes you configured right network name and password or No, you cannot connect with name and password... change something and retry
    Do you think that Network Manager can help with this?
    – Sandro Varoli Sep 20 '22 at 07:44
  • I'm confused. Your question was: "How to just check Wifi Access Point connectivity" but your comment here says: "I know how to get ESSID list and how to test if the network is connected." Sorry but I haven't any other suggestions. – chili555 Sep 20 '22 at 14:22
  • Maybe I was not clear. I have not to perform this for myself. I need a script that will be run on devices on industrial plants where nobody know anything about Linux. So I need to ask people ESSID, PASSWORD and then say to them Ok device can connect, or Device cannot connect... then script will ask them if they want to save and apply or quit. What I miss is: How to automate this in a background process that only returns to main script Connection OK/KO? – Sandro Varoli Sep 20 '22 at 15:00
  • Sorry, I know very little about writing scripts. nmcli clearly shows available networks and says either Error: Connection activation failed or else Device 'wlp3s0' successfully activated where wlp3s0 is the relevant interface. – chili555 Sep 20 '22 at 15:27

0 Answers0