Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Perform an action when network cable unplugged (and back in again)



On Wed, Jun 13, 2012 at 9:24 AM, Darren Cook <darren@example.com> wrote:
My notebook, running ubuntu 10.04, is almost all the time using a wired
connection, with static IP address. When I pull the network cable out of
my notebook (and then plug it in again) I see these entries in /etc/syslog:

Jun 12 09:04:45 myhost kernel: [479179.526691] r8169: eth0: link down
...
Jun 12 09:08:40 myhost kernel: [479414.948768] r8169: eth0: link up

What I'd like to do is run a command when we get link down (I'd like to
unmount a network drive), and run another command when we get link up
(remount the drive). Are there any hooks in linux for this? (I know we
have if-up.d and if-down.d for the interfaces, but those scripts are not
being run when just the cable is pulled out; I'm looking for the "link"
equivalent of those directories.)

Does such a thing even exist?


It does exist.

http://stackoverflow.com/questions/10340145/get-event-for-nic-ethernet-card-link-status-on-linux

I don't have time to program it for you right now, but it seems one can handle netlink socket connections through python:

http://stackoverflow.com/questions/4676866/how-can-i-use-a-netlink-socket-to-data-from-kernel-space-in-python

This looks promising at least..

--
Sincerely yours,

Jawaad Mahmood
http://www.jawaadmahmood.com
080-4204-7198

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links