Score:0

Event driven way to detect Ethernet port status changes (disconnected / 10mb / 100mb / etc) in linux?

pt flag

I was wondering if linux has some sort of interface to detect ethernet port state changes via /sys or some other way that is event driven.

What I mean by state changes is DISCONNECTED / 10mbit / 100mbit / etc.

We could just pool the status of the port every X ms, but I was hoping on using inotify to watch for something that changes on the filesystem and trigger our action based on that.

We are actually most interested in changes from 10mbit to 1gbit. So having something that only triggers on connected / disconnected would not be sufficient.

Any ideas?

user10489 avatar
nc flag
If it was just connection, I think there is both a dbus event and a systemd event. But if you want speed, I'm not sure... I poll the speed on one of my systems using ethtool and grep about once every 2-3 minutes.
pt flag
Thanks for the pointer... I need something more real time than 2-3 minutes... I'm debating watching dmesg and just parsing the log entry out of there if a match hits. Looks like this will probably be the solution I end up using.
A.B avatar
cl flag
A.B
If a carrier down/up event always precedes a speed change, you just have to wait for such even (`ip monitor link dev eth0` or dbus, NM, systemd...) and then poll the speed.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.