LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   test to see if eth0 is active (https://www.linuxquestions.org/questions/linux-networking-3/test-to-see-if-eth0-is-active-654678/)

DragonM15 07-09-2008 03:30 PM

test to see if eth0 is active
 
Ok, heres the deal. I am making a bash script that checks to see if the ip address is in a certain range, and proceeds to backup data to a server. I did this by grepping ifconfig for a certain ip range. However this script is going to be ran on a laptop that will be plugged and unplugged from the network. If you run ifconfig when the laptop isnt plugged in but the nic is turned on, it keeps the ip address from the last time you ran dhcpcd, even though it isn't plugged in at the time.

What I need is a way to tell if the ethernet cable is plugged in or not. Is there a way to do this?

Thanks,
DragonM15

farslayer 07-09-2008 03:53 PM

possibly with ethtool ..

it-etch:/# ethtool eth0 | grep Link
Link detected: yes

DragonM15 07-09-2008 04:00 PM

That was exactly what I was looking for. Works like a charm! Thanks for your quick reply.

DragonM15


All times are GMT -5. The time now is 01:08 PM.