You are here

network manager - script to disable wifi when using ethernet

i have a docking station for my laptop. so i dont always use wifi. i have also configured static ip addresses for both wifi and cable connections. the same ip address for both.

so i sat down and wrote a script to be run by crontab every minute that would check to see whether i was on the ethernet cable or using the wifi connection. and it would disable the other. i have commented out info messages as i use it from crontab very succesfully. also this script can be run as a normal user.


/bin/nmcli d |grep ethernet |grep connected > /dev/null

if [ $wired -eq 0 ]
#       echo "INFO: em1 in use"
        if [ `nmcli r| awk '{print $2}'| tail -1` == "enabled" ]
#               echo "INFO: Wifi enabled"
#               echo "INFO: Turning radio off"
                nmcli radio wifi off
#       echo "INFO: Turning radio on"
        nmcli radio wifi on