Ubuntu: Ethernet to Wifi Rollover when Eth0 is Disconnected



Question:

#!/bin/sh  eth0_status=$(cat /sys/class/net/enp0s25/operstate)  wlan0_status=$(cat /sys/class/net/wlx944452988614/operstate) conn=$(nmcli n connectivity)  if [ "$eth0_status" = "down" ] && [ "$wlan0_status" = "up" ] && [ "$conn" = full ] ; then      contest=$(curl -s -f ifconfig.co)      if [ -n "$contest" ] ; then              curl here (had to remove)      fi      if [ -z "$contest" ] ; then              nmcli con down id HOME-A0B2 ; sleep 2 ;              nmcli radio wifi off ; sleep 1 ;              nmcli radio wifi on ; sleep 2 ;              nmcli con up id HOME-A0B2 ; sleep 5 ;              sh /opt/portmapper/mapcheck.sh              curl (had to remove)      fi  fi  if [ "$eth0_status" = "up" ] && [ "$wlan0_status" = "up" ] && [ "$conn" = full ] ; then      nmcli con down id HOME-A0B2 ; sleep 1 ;      nmcli radio wifi off ; sleep 5 ;      conn=$(nmcli n connectivity)      contest=$(curl -s -f ifconfig.co)      if [ -n "$contest" ] && [ "$conn" = full ] ; then              sh /opt/portmapper/mapcheck.sh              curl (had to remove)      fi      if [ -z "$contest" ]  && [ "$conn" = none ] ; then              nmcli radio wifi on ; sleep 5 ;              nmcli con up id  HOME-A0B2 ; sleep 1 ;              curl (omitted)      fi   fi   if [ "$wlan0_status" = "down" ] && [ "$eth0_status" = "down" ] ; then      nmcli radio wifi on; sleep 2;      nmcli con up id HOME-A0B2; sleep 5;      sh /opt/portmapper/mapcheck.sh      nmcli g     fi   if [ "$wlan0_status" = "up" ] && [ "$eth0_status" = "up" ] && [ "$conn" = none ] ; then      nmcli n disabled; sleep 1;      nmcli n enabled; sleep 2;      nmcli g   fi     exit  

Okay this has got to be my most confusing and worse code yet. All I want to do is create a script that automatically rolls over to Wifi antannae and autoconnects to wifi when the ethernet is plugged in. I had it working on Linux Mint 16 but I rolled over to 17.1 and it stopped working. I have since changed it trying to get it to work and this is no where near where it used to be. This is just some garbage I have so far. It does not work and does not roll over to Wifi. Also this goes in the /etc/NetworkManager/dispatcher.d/ and will be ran upon change like the old script that I used was in there and worked perfectly. I dont know where it went but was on a forum asking someone on there and they helped. Can someone help. Probably need to start from scratch. Ubuntu or Linux Mint does not do this automatically in the Ifup/Ifdown parts unless I do not have it enabled.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »