[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ethernet card question



On 21/03/2005 at 13:34 -0400, Rolando Abarca wrote:

> is there a way to know if there's a cable connected to the ethernet 
> card?... I ask this because I have a lombard powerbook, with a dhcp 
> configured eth0, but if I boot GNU/Linux (ubuntu hoary) it stops waiting 
> for a dhcp server, I would like to modify the networking script, so if 
> there's no cable present on the card, don't configure the eth0 device, 
> only the loopback. Is it possible?

If the driver supports something as ethtool, yes.

I've removed the auto stanza of eth0 in /etc/network/interfaces, and put
this little script in /etc/rc.boot/check-eth :

---8<---
#! /bin/sh

echo2 () {
    echo "$*" >&2
}

die () {
    echo2 "$*"
    exit 2
}


IFACE=eth0

LINKSTATE=`/usr/sbin/ethtool $IFACE | grep -i link\ detected`
LINKDETECTED=`echo $LINKSTATE | awk '{ print $3 }'`

case "$LINKDETECTED" in
     "no") echo2 "$IFACE: cable disconnected"
           /sbin/ifdown $IFACE 2>/dev/null
           /sbin/ifconfig $IFACE down
           ;;
    "yes") echo2 "$IFACE: cable connected"
           /sbin/ifdown $IFACE 2>/dev/null
           /sbin/ifconfig $IFACE down
           /sbin/ifup $IFACE
           ;;
        *) die "ERROR: LINKSTATE not handled: .$LINKSTATE."
           ;;
esac
--->8---

I have an iBook G3; it's ethernet interface works with both gmac and
sungem drivers. This only works with the sungem one (because gmac does
not support ethtool).

-- 
Kiko
Private mail is preferred encrypted:
http://www.pirispons.net/pgpkey.html



Reply to: