[Top][All Lists]

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

Re: [Help-bash] eth0 up or down?

From: Mike McClain
Subject: Re: [Help-bash] eth0 up or down?
Date: Sun, 23 Apr 2017 21:56:49 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

> On Sun, Apr 23, 2017 at 8:08 AM, Mike McClain <address@hidden>
> wrote:
> > Howdy,
> >     How can I tell from bash whether eth0 is up or down that would be
> > faster or less expensive than $(ifconfig eth0;)? Is there some where
> > in /proc or elsewhere in memory a bash program can reach?
> Pierre Gaston <address@hidden> replied:
> You don't mention the OS you are targeting,  you might be able to do
> something like: $(</sys/class/net/eth0/operstate).
> Though if you are not running this in a quick loop the price you pay for a
> fork is probably not a problem

Thanks Pierre,
    That will do nicely.
Oops, you're right, Debian Linux so your advice was spot on.

Your pointer allowed me to find this substitution too:
>From this:
    pk=$( ifconfig $eth | awk '/TX packets:/{print $2;}' )
    pkts=${pk#*:};              #   packet count
To this:
    #   due to address@hidden
    pkts=$(< /sys/class/net/eth0/statistics/tx_packets)

Which will obviously will be quicker. I'm using 'old iron',
P3 1/2M ram so try to be frugal with bytes and time.
It's just a little script to bring eth0 down if I'm doing something
else but I want to show as little footprint as needful.
Thanks again for your help.
    Toward a happier life, always hang up immediately you've found
you've been called by a machine. - MM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]