[SOLVED] How to connect to a wifi network by shell script?

Post here if you are a new Porteus member and you're looking for some help.
hope
Black ninja
Black ninja
Posts: 64
Joined: 04 Jul 2020, 12:07
Distribution: porteus 5.0rc1 KDE desktop

[SOLVED] How to connect to a wifi network by shell script?

Post#1 by hope » 11 Jun 2023, 11:24

Hi to all.
I want to add a new network(wifi network by its configurations, connection name, ssid, passwd etc.) by using shell script to my Porteus, I am using Porteus in usb stick therefore I do not want to enter all configurations all time by hand again and again. Is is possible to add a new network by using shell scripting? What I achieve is that, I wrote all config in a file and shell script read all those and add new wifi network connection to Porteus and I can only click "connect" and connect to my wireless connection.

I can handle coding part, I only want to know and guide about :
1. is is possible and,
2. where do I have to look for (i.e. man page of which commands ? what is the shell command behind network clients? etc.

Thanks.
[edited my question and add more info about what I want to achieve.]
Last edited by hope on 11 Jun 2023, 13:07, edited 1 time in total.
Newbie to Linux-Unix systems, try to read,learn, apply, modify and create.

hope
Black ninja
Black ninja
Posts: 64
Joined: 04 Jul 2020, 12:07
Distribution: porteus 5.0rc1 KDE desktop

How to connect to a network by shell script?

Post#2 by hope » 11 Jun 2023, 13:07

I think I found all commands I need in
https://developer-old.gnome.org/Network ... nmcli.html.

example :

Code: Select all

nmcli dev wifi con "Cafe Hotspot 1" password caffeine name "My cafe" 
given in the page will solve my problem.
Newbie to Linux-Unix systems, try to read,learn, apply, modify and create.

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

[SOLVED] How to connect to a wifi network by shell script?

Post#3 by Ed_P » 11 Jun 2023, 20:29

A very impressive find hope. Hopefully you will post a copy of your script when you're done. (obviously with tweaked passwords)
Ed

hope
Black ninja
Black ninja
Posts: 64
Joined: 04 Jul 2020, 12:07
Distribution: porteus 5.0rc1 KDE desktop

[SOLVED] How to connect to a wifi network by shell script?

Post#4 by hope » 11 Jun 2023, 20:43

Ed_P wrote:
11 Jun 2023, 20:29
A very impressive find hope. Hopefully you will post a copy of your script when you're done. (obviously with tweaked passwords)
Thanks Ed_P, actually at first, my script contained only one command line like :

Code: Select all

#!/bin/sh
nmcli dev wifi connect "ssid-of-wifi" password 123 name wifi1 hidden yes
Then, after finding that Porteus is using NetworkManager, I searched more and I found in that https://stackoverflow.com/questions/354 ... sing-nmcli. It helps me to get more scriptable commands(Pocokman's answer), and I improved my script as :

Code: Select all

#!/bin/sh
nmcli c add type wifi con-name wifi1 ifname wlan0 ssid "ssid-of-wifi"
nmcli con modify wifi1 wifi-sec.key-mgmt wpa-psk
nmcli con modify wifi1 wifi-sec.psk 123
nmcli con up wifi1
:)
Newbie to Linux-Unix systems, try to read,learn, apply, modify and create.

Post Reply