Article 6EG86 How can add rfkill command in the service setting?

How can add rfkill command in the service setting?

by
luofeiyu
from LinuxQuestions.org on (#6EG86)
Insert my wireless network card,get the wifi interface name:

sudo iwconfig
wlx001a8c3008b1

Get ESSID name with wireless network card:

sudo iwlist wlx001a8c3008b1 scan | grep ESSID
ESSID:"ap_name"

I wan to connect the AP with command.
Install wpasupplicant:
Code: sudo apt install wpasupplicant
wpa_passphrase ap_name xxxx | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.confSet it as a service:
Code: sudo vim /lib/systemd/system/wpa_supplicant.service
[Unit]
Description=WPA supplicant
Before=network.target
After=dbus.service
Wants=network.target
IgnoreOnIsolate=true

[Service]
Type=dbus
BusName=fi.w1.wpa_supplicant1
ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx001a8c3008b1

[Install]
WantedBy=multi-user.target
Alias=dbus-fi.w1.wpa_supplicant1.serviceSet a dhclient service:
Code: sudo vim /etc/systemd/system/dhclient.service
[Unit]
Description= DHCP Client
Before=network.target
After=wpa_supplicant.service

[Service]
Type=forking
ExecStart=/sbin/dhclient wlx001a8c3008b1 -v
ExecStop=/sbin/dhclient wlx001a8c3008b1 -r
Restart=always

[Install]
WantedBy=multi-user.targetNow it is time to connect the AP:
Code: sudo rfkill unblock wlan
sudo systemctl start wpa_supplicant
sudo systemctl start dhclientI can connect AP `ap_name` with above three commands.How can simplify three commands as two commands?How can add ` sudo rfkill unblock wlan` into wpa_supplicant service ?

Code: ExecStart=/usr/sbin/rfkill unblock wlan ; /sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx001a8c3008b1
ExecStart=/usr/sbin/rfkill unblock wlan && /sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx001a8c3008b1
ExecStart=/usr/bin/bash -c "/usr/sbin/rfkill unblock wlan && /sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx001a8c3008b1"None of them can work!How can add rfkill command `/usr/sbin/rfkill unblock wlan` in the service setting `wpa_supplicant.service`?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments