6

Can I get the status of a process by using the HDD and Power LEDs as indicators?

I'd like to use the green power LED to tell me that a status is available, and the red LED to tell me that it isn't.

2 Answers 2

4

HDD leds are normally tied to the hard drive controller. There isn't a way for an operating system on a PC to make it light up other than by causing some hard drive activity. Neither accessible to the OS is the power led.

What's easier is to use the keyboard LEDs for this purpose. Since you are indicating Ubuntu in your tags, you may want to look at a program called ledd ledcontrol.

4
  • can you help me in keyboard led light to some process? i use server...
    – Marcell
    Jul 12, 2012 at 15:26
  • 1
    pwet.fr/man/linux/administration_systeme/ledd - and I'm sorry the name of the package is actually ledcontrol - Probably going to have to write a wrapper script to turn on the ledd when your process starts and turn it off when it finishes.
    – LawrenceC
    Jul 12, 2012 at 15:32
  • so when my process is available the led turn on and when offline turn it off? :D
    – Marcell
    Jul 12, 2012 at 15:34
  • 1
    ledcontrol is flexible, but unfortunately can't be "attached" to a process to automatically display status. You may need to write a wrapper script, write a cron job, use i/dnotify, or other mechanism to check on the status and refresh the LED's according to the state of process. There may be other tools that do something similar that I'm not aware of.
    – LawrenceC
    Jul 12, 2012 at 15:48
6

On a linux box, you can see and affect the state & brightness of various LED's through the /sys/class/leds subdirectories.

On my system:

> ls -l /sys/class/leds/
lrwxrwxrwx 1 root root 0 Jul 12 19:36 ath5k-phy0::rx -> ../../devices/pci0000:00/0000:00:14.0/0000:07:00.0/leds/ath5k-phy0::rx/
lrwxrwxrwx 1 root root 0 Jul 12 19:36 ath5k-phy0::tx -> ../../devices/pci0000:00/0000:00:14.0/0000:07:00.0/leds/ath5k-phy0::tx/

Let's look in the ath5k-phy0::rx subdir:

> ls -l
drwxr-xr-x 2 root root     0 Jul 12 21:26 power/
-rw-r--r-- 1 root root 4,096 Jul 12 21:26 brightness
lrwxrwxrwx 1 root root     0 Jul 12 21:26 device -> ../../../0000:07:00.0/
-r--r--r-- 1 root root 4,096 Jul 12 21:26 max_brightness
lrwxrwxrwx 1 root root     0 Jul 12 19:36 subsystem -> ../../../../../../class/leds/
-rw-r--r-- 1 root root 4,096 Jul 12 21:26 trigger
-rw-r--r-- 1 root root 4,096 Jul 12 19:36 uevent

If you examine the contents of the files shown, it gets interesting.

look in trigger, you can see what 'built-in' triggers are available, and which one is currently in use:

> cat trigger 
none ADP1-online BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid rfkill0 rfkill1 [phy0rx] phy0tx phy0assoc phy0radio rfkill2 

Find the entry with the square brackets (towards the right), it shows that this LED is being controlled at the moment by the wireless receiver status. It glows orange (on this system) when it receives a packet.

You can echo a name to this trigger file to change what controls it. Want to show when the battery is charging-or-full?

(as root!)
> echo BAT0-charging-or-full > trigger

If you set the controller to none, then YOU can output values to the brightness file to control the on/off of the LED.

Always good to refer to the kernel documentation for more information. GIYF

I've played with this in the past, but nothing real recent. What LED's are available are solely based on your hardware and kernel drivers/modules. YMMV.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .