How to flash LEDs on copper ETH RJ-45 NIC's port by shell script?

Hi, FreeBSD Gurus!

How to flash LEDs on copper ETH RJ-45 NIC's port by shell script?

I need to physically identify certain port on back of my servers with a lot of NICs each of them have 2-4 ETH ports.

For now I find this solution (on StackExschange, not tested) but may be You propose a much better way than just text on screen and playing with cable jack:

Perl:
use strict;
my $intf = "igb0";

while (1) {
    foreach my $state (qw/up down/) {
        system("ifconfig $intf $state\n");
        sleep 3;
    }
}

Ideal would be solution where script give me list of NICs interfaces WITH their state (UP/DOWN, ACTIVE), speed and IP, and waiting to interface name entering to 7-10s blinking by one of LED.
(Of course in case when port active and sending/receiving data, script must using other that already blinking LED...)

Thank You so much for detailed explanation.
 
Last edited by a moderator:
Typically the LEDs are "one for physical link, the other for activity". A lot of the configuration for the LEDs is done in the device driver, the LEDs are usually connected directly to the PHY on the interface, not sure how many drivers actually expose control of that to userspace.

If by using the ifconfig command to down/up an interface and the LED follows that state that's about the best you are probably going to do.

ifconfig -a gives you a list of all interfaces, the UP/DOWN state is on the same line as the interface name so should be able to create a script that runs the return of ifconfig -a and gets you interface name and current state, then you have a loop running all interfaces except for lo and other virtual interfaces (I think you need to look at media line), then an inner loop toggling state.


That's about the best I can give you.
 
Have a look at /dev/led/ and the manpage for your specific NICs. Not all (actually very few) support manual activation of the LEDs for identification.
em(4) mentions the led(4) API:
The identification LEDs of the adapters supported by the em driver can be controlled via the led(4) API for localization purposes.

IIRC some drivers support blinking the LEDs via sysctls, but as you see: this is beyond any standardization, so I doubt there is any (or at least an easy) way to script that to universally work on any given NIC...

Usually it is WAY easier to just look at the MAC-tables on the switch and match the corresponding ports. Most switches also support port identification via LED.
 
Answering the 2nd part:

Down all the other interfaces, grab a cat 5 cable and plug it into a switch.
Try each NIC, whichever lights up is the one you want.
 
Typically the LEDs are "one for physical link, the other for activity". A lot of the configuration for the LEDs is done in the device driver, the LEDs are usually connected directly to the PHY on the interface, not sure how many drivers actually expose control of that to userspace.
Thank You for explanation.

Let’s start with Intel-based NICs, because that’s a most stable and well designed drivers.

If by using the ifconfig command to down/up an interface and the LED follows that state that's about the best you are probably going to do.
That’s also my tough before I wrote topic.

ifconfig -a gives you a list of all interfaces, the UP/DOWN state is on the same line as the interface name so should be able to create a script that runs the return of ifconfig -a and gets you interface name and current state, then you have a loop running all interfaces except for lo and other virtual interfaces (I think you need to look at media line), then an inner loop toggling state.
Great solution, thank You!
But I try to find solution with physically identifying by blinking's LED...

That's about the best I can give you.
TNX! :)
 
Last edited:
Back
Top