How can I detect if a NIC is UP in UNIX?

Posted by Rich on Super User See other posts from Super User or by Rich
Published on 2010-09-17T12:11:11Z Indexed on 2012/11/29 17:08 UTC
Read the original article Hit count: 210

Filed under:
|
|

I am currently writing a bash script (for Nagios), and I would like to be able to detect if specific network cards are up or not.

My best guess is to do something like this:

ifconfig eth0 | grep UP | wc -l

or:

 ethtool eth0 | grep "Link detected: yes" | wc -l

Are either/both of those reliable ways of testing if the network card is up, or is there a better option? Perhaps there is a flag on ethtool which will do precisely what I want?

Thanks in advance for any suggestions/pointers!

Rich

© Super User or respective owner

Related posts about networking

Related posts about bash