-   Linux - Newbie (
-   -   Is there a cli command for logging the status of a NIC - eth0 (

baracooda 01-20-2010 08:03 PM

Is there a cli command for logging the status of a NIC - eth0
I would like to know if it's possible to create a continual log for a network interface card's status. That is whether it's up or down and time and date stamped if possible.
I'm wondering if there is a cli command that exists to do this
I've looked at "ethtool" but this only sets the parameters of the nic.
Also looked at the log files that I could find /dev/log var/log, but there is no mention of a status for eth0.

evo2 01-20-2010 08:23 PM

The sys file system provides *heaps* of information. For example /sys/class/net/eth1/operstate for up/down information
Or for a whole bunch of detailed information have a look at the files in /sys/class/net/eth0/statistics/



baracooda 01-20-2010 09:23 PM

Thank you for the info evo2, certainly put me in the right direction.
Unfortunately /sys/class/net/eth0/operstate only provides the status of the
eth0 at the time of viewing and is not appended but update as the state changes.

I was hoping more along the lines of date and time stamp for status change,
similar to a startup / shutdown log under sys.

cantab 01-20-2010 10:01 PM

Depending on time interval, you could either create a cron job, or run a bash script.
For example

while true ; do cat /sys/class/net/eth0/operstate >> network_stats ; sleep 60 ; done
The number after sleep is the time to wait in seconds. So this example takes the stats every minute.
If you only want to log changes, you could do more sophisticated stuff, probably using grep and sed.

All times are GMT -5. The time now is 06:14 PM.