Skip to content

Instantly share code, notes, and snippets.

@tmonjalo
Last active December 11, 2023 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmonjalo/6da7a576e35a4cd2a968894c693ae7f4 to your computer and use it in GitHub Desktop.
Save tmonjalo/6da7a576e35a4cd2a968894c693ae7f4 to your computer and use it in GitHub Desktop.
Toggle wifi status on ethernet event with Linux NetworkManager
#! /bin/sh
# path should be /etc/NetworkManager/dispatcher.d/99-auto-wireless
self=${0##*/}
log() { logger -p user.info -t "${self}[$$]" "$*" ;}
iface=$1
action=$2
case $iface in eth*|usb*|en*)
case $action in
up)
log "disabling wifi"
nmcli radio wifi off ;;
down)
[ -z "$(ip route show to default)" ] || exit 0
log "enabling wifi"
nmcli radio wifi on ;;
esac
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment