DEBIAN
NETWORKING NETWORKING
CONFIGURE IP IN UBUNTU
How to check the physical cable if it's alive.
$ sudo ethtool eth0
or
$ sudo ethtool eth0 | grep Link Link detected: yes
Alternative:
mii-tool
To work around using script.
You could try this:
gw="$(ip route | awk "/^default via/ {print \$3}")" ping -c 1 "$gw" > /dev/null result="$?"
Options option:
use this command to check a wire is connected:
cd /sys/class/net/ grep "" eth0/operstate
If the result will be up or down. Sometimes it shows unknown, then you need to check
eth0/carrier
It shows 0 or 1
cat /sys/class/net/ethX is by far the easiest method.
The interface has to be up though, else you will get an invalid argument error.
So first:
ifconfig ethX up
Then:
cat /sys/class/net/ethX
some ways, including ifconfig|grep RUNNING, ethtool, cat /sys/class/net/eth0/carrier, but all they require that the interface is up.