Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a script when the switch goes down and an other when it goes up. Is there an easy way to pull this off in Debian (preferably with no other than system tools)?

I suppose there is no difference (in the OS point of view) between unplugging ethernet cable and the switch losing power.

On an event I get lines like these in the syslog:

Jun 15 17:49:41 debian kernel: [ 5506.956130] igb: eth1 NIC Link is Down
Jun 15 17:49:45 debian kernel: [ 5511.168788] igb: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX/TX

In FreeBSD you can pipe log messages (pre-filtered by regex patterns) to a program. What is the easiest way to replicate this on Debian (with as little additional software as possible)?

share|improve this question

You can add a pre-up, post-up, pre-down, and post-down directives to your /etc/network/interfaces file to achieve this.

For example:

auto eth0
iface eth0 inet static
    name Ethernet LAN card
    post-up /etc/network/if-up.d/somescript.start

This article has some additional examples.

share|improve this answer
Thanks, I'll give it a try first thing in the morning. – vbence Jun 15 '11 at 20:47
This does not seem to work. It won't detect the loss of connection. It will only be called in the process of bringing up the interface when I type: ifup eth0. – vbence Jun 15 '11 at 23:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.