Last active
December 11, 2021 23:40
-
-
Save sophieforceno/bf137b32759ea5be8b91 to your computer and use it in GitHub Desktop.
A Bash script that enables/disables network adapters depending on connectivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# net-adapt v0.9 (build 110915) | |
# | |
# Enables and disables WIFI device depending on ethernet connectivity | |
# by Sophie Forceno | |
# | |
# Distributed under an "I-don't-care-what-you-do-with-this" license | |
while true | |
do | |
eth0_status=$(cat /sys/class/net/eth0/operstate) | |
wlan0_status=$(cat /sys/class/net/wlan0/operstate) | |
# Disable wifi when cable is plugged in | |
if [[ "$eth0_status" = "up" ]]; then | |
nmcli nm wifi off | |
# Enable wifi when ethernet cable is unplugged | |
elif [[ "$eth0_status" = "down" ]] && [[ "$wlan0_status" = "down" ]]; then | |
nmcli nm wifi on | |
fi | |
sleep 2s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment