You are not logged in.

#1 2023-06-05 06:34:23

Utini
Member
Registered: 2015-09-28
Posts: 453
Website

SOLVED dispatcher script (disable wifi on ethernet) doesnt do anything

Hi guys,

there is a example script in the Arch wiki but it isn't very handy when using a laptop which connects to different docking stations / ethernet dongles which change the name of the "LAN_Interface" frequently.

So here is a better approach I found online but it doesn't do anything for me?

#!/bin/bash

enable_disable_wifi ()
{
    result=$(nmcli dev | grep "ethernet" | grep -w "connected")
    if [ -n "$result" ]; then
        nmcli radio wifi off
#	echo "off"	
    else
        nmcli radio wifi on
#	echo "on"
    fi
}

if [ "$2" = "up" ]; then
    enable_disable_wifi
fi

if [ "$2" = "down" ]; then
    enable_disable_wifi
fi

Output of "nmcli dev | grep "ethernet" | grep -w "connected":

enp52s0f3u1u3u4  ethernet  connected               My Ethernet

The script is in:

/etc/NetworkManager/dispatcher.d/
-rwxr-xr-x 1 root root  342  5. Jun 08:17 70-wifi-wired-exclusive.sh

Any ideas? :S

Last edited by Utini (2023-06-07 11:57:54)


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#2 2023-06-05 07:21:51

seth
Member
Registered: 2012-09-03
Posts: 53,312

Re: SOLVED dispatcher script (disable wifi on ethernet) doesnt do anything

https://wiki.archlinux.org/title/Networ … plugged_in

Note: You can get a list of interfaces using nmcli. The Ethernet (LAN) interfaces start with en, e.g. enp0s5

[[ "enp0s5" = "en"* ]] || [[ "eth1" = "eth"* ]] && echo foo
[[ "ep0s5" = "en"* ]] || [[ "et1" = "eth"* ]] && echo foo

Offline

#3 2023-06-06 05:11:20

Utini
Member
Registered: 2015-09-28
Posts: 453
Website

Re: SOLVED dispatcher script (disable wifi on ethernet) doesnt do anything

Thanks but I managed to fix it simply by not running it manually.
It seems the script only triggers/works when the ethernet cable is plugged in or unplugged but not when running the script manually (and changing the status manually as well).


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#4 2023-06-06 07:07:30

seth
Member
Registered: 2012-09-03
Posts: 53,312

Re: SOLVED dispatcher script (disable wifi on ethernet) doesnt do anything

It seems the script only triggers/works when the ethernet cable is plugged in or unplugged

Yes, that's the point of the test inside the script.

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

Board footer

Powered by FluxBB