Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 07-09-2008, 03:30 PM   #1
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Rep: Reputation: 31
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?

Old 07-09-2008, 03:53 PM   #2
LQ Guru
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,243
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
possibly with ethtool ..

it-etch:/# ethtool eth0 | grep Link
Link detected: yes
Old 07-09-2008, 04:00 PM   #3
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
That was exactly what I was looking for. Works like a charm! Thanks for your quick reply.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Eth0 is not active after boot toes Linux - Wireless Networking 3 07-23-2006 04:34 PM
Cannot ping self ??? eth0 not active ??? Wynand1 Linux - Networking 2 06-29-2006 12:11 AM
howto test if an ethernet device is active six6 Programming 1 01-28-2005 02:39 AM
interface eth0 is not (yet?) active jorcas SUSE / openSUSE 1 11-22-2004 06:53 PM
eth0 not active on startup rocket84 Linux - Networking 6 07-21-2003 01:09 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration