LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-27-2006, 01:39 PM   #1
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Detect network cable being plugged in


Hi all,
When I plug or unplug my network cable (from eth0, a standard 10/100 nic), and use "dmesg", I see status notices like:
Code:
eth0: network connection down
eth0: network connection up using port A
My question: is there a way to detect these changes without using dmesg? Perhaps something changes in /proc/ or some event I could listen to? Basically I want to run a simple script when the network cable is plugged in. I have tried ifplugd, but it didn't seem to work properly for me.
Any ideas / advice?
 
Old 06-27-2006, 03:46 PM   #2
cwwilson721
Senior Member
 
Registered: Dec 2004
Location: In my house.
Distribution: Ubuntu 10.10 64bit, Slackware 13.1 64-bit
Posts: 2,649
Blog Entries: 1

Rep: Reputation: 67
Did you try the scripts at Alien Bobs site? They work like a charm for me. Just change all of them at once to be sure everything works right.
 
Old 06-28-2006, 11:00 AM   #3
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Original Poster
Rep: Reputation: 31
Thanks for the link, it looked like a good soluation, but then I realized it basically wraps ifplugd (and libdaemon), which I still haven't had any luck with.
Any more ideas? If not I guess I will have to write some sort of dmesg watching script
 
Old 06-28-2006, 11:09 AM   #4
katayamma
Member
 
Registered: Jan 2006
Posts: 37

Rep: Reputation: 15
Have you tried syslog? It can log kernel messages that show up in dmesg and you can send output to the console. If you don't want to see all the kernel message ring data, you could log to a file and tail it to the console as a background process with a grep for just ethernet messages.

Not very elegant, but it's a quick hack & slash for what you want.

(Note: That's according to the man page for dmesg. I haven't bothered to test it.)
 
Old 06-28-2006, 11:14 AM   #5
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
Quote:
Originally Posted by Vgui
it basically wraps ifplugd (and libdaemon), which I still haven't had any luck with.
Why don't you just give it a try? Can you tell me what went wrong with your own ifplugd experiences?

Eric
 
Old 06-28-2006, 11:24 AM   #6
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Original Poster
Rep: Reputation: 31
Code:
tail -f /var/log/syslog | grep "eth0: network connection up"
That seems to get me the notification I want; I can latch onto it and call my script when it changes.
I like this solution a bit better for 2 reasons: it's simple and clean, and it doesn't require 2 additional software packages (even if they are tiny).
So although I imagine your script is very useful Alien Bob, it is probably overkill for my needs in this situation. And since I didn't elaborate earlier, the problem I was having with ifplugd was it did not trigger anything when the cable was un/plugged. I could see the process running in 'ps', but it didn't seem to actually do anything. I imagine I could have dug deeper and tried different configurations, but the tail solution seems fine for now.

Thanks a lot everyone!
 
Old 06-28-2006, 12:20 PM   #7
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
FYI,
If you want sophisticated logfile monitoring with action triggers, take a look at SEC (simple event correlator) at http://www.estpak.ee/~risto/sec/
I've used this, and found it practical and useful. It's basically no more than one intelligent perl script that can daemonize itself.

Eric
 
Old 01-03-2009, 06:22 AM   #8
tiekookeit
LQ Newbie
 
Registered: Jan 2009
Location: Brazil
Distribution: debian
Posts: 16

Rep: Reputation: 1
I scripted this, and its work to me,



if [ "`ifconfig eth0|sed -n '/running/I p'`" == '' ];then echo off;else echo on;fi

change eth0 by e eth device you want to.


Good Luck!

Visit Brazil, it a nice place
 
  


Reply



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
if( ethernet-cable-is-plugged-in ) { ... mrtwice Linux - Networking 13 10-08-2006 02:57 PM
plugged in lan cable, still "not connected'' message shows New@Mandrake Linux - Networking 5 10-14-2004 11:56 AM
What happens when a network cable is plugged in ? balajipriya Linux - Networking 1 08-12-2004 09:10 AM
dhcpcd, no network cable plugged in meyert Slackware 3 04-28-2004 08:34 PM
Automatically Connect when cable is plugged in?? NovaBurst Fedora 2 02-18-2004 09:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:49 AM.

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