Solution: Blinking Access Light (BASH Script)

So, just for fun, I decided to write up a blinking Disk Access IO LED script since I did not find a natural way to watch my hard drive in action. If you have another method that turns on disk activity LED, please feel free to post up and I’ll delete my script.

edit: I had to modify the script to allow a little breathing room for the slow processors. I added the 1 second sleep per loop and a 2 second sleep when the activity light lights up.

edit: one more thing, make sure the led lights are on under settings/Energy Saver/LED = ON

just copy and paste it into a text file called ioled.sh

#-------------------------cut here ------------------------------------------------------------

#!/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

source /usr/local/sbin/drive_helper.sh
[-f /usr/local/sbin/ledConfig.sh] && . /usr/local/sbin/ledConfig.sh

dataVolumeDisk=basename ${dataVolumeDevice}
led=0
while :; do

   iow=awk -v disk="${dataVolumeDisk}" '{if ($3==disk) print $12}' /proc/diskstats

   if [$((iow)) -eq 0]; then

      if [$((led)) -eq 1]; then
         ledCtrl.sh LED_EV_HALT LED_STAT_OK
         led=0
      fi
   else
      if [$((led)) -eq 0]; then
         ledCtrl.sh LED_EV_DISK_STBY LED_STAT_OK
         led=1

         sleep 2 #let the light stay on for a longer duration
      fi
   fi

   sleep 1  #allows some processor time between loops
done

#-------------------------cut here ------------------------------------------------------------

if you created the text file ioled.sh and saved it in your Public shares, you can find it in /shares/Public/ioled.sh

after you SSH into the device,

chmod 755 ioled.sh

Then you can run it at the prompt by

./ioled.sh

or you can use the ampersand at the end of the name for it to run in the background like this

./ioled.sh&

then you can exit the SSH, otherwise if you exit without the &, the script will stop when you exit SSH.

to run it at the lowest priority, you can use the “nice” command as follows

nice -19 ./ioled.sh&

and query how nice it is running

ps -fl -C “ioled.sh”

F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD

0 S root     24700 11481 11  99  19 -   564 pipe_r 21:14 pts/1    00:00:00 /bin/bash ./ioled.sh

So if you like this post, click on the star beside my name to give me kudos and I’ll be encouraged to share more. 

Thanks for reading…

1 Like

That must have been a very dark corner backstage where you got this inspiration.

You should know that some proud genius at WD software dept. diligently developped what experts call a “state machine” in order to make sure that this marvelous LED always is in a legal state!

I suggest you do your homwork and instead of fiddling with ugly bash code you add the necessary states to that **bleep** state machine!!

“Law and order” - you know?

Count Dooku

1 Like

Actually I do know why WD took the led IO light out… back when we had the WD Live, we thought we were hacked when the little green light kept blinking on and off constantly for two years; at that time we didn’t know that it was the media scan.

so WD removed this feature along with setting the sleep timer to 10 minutes permanantly; true story :stuck_out_tongue:

You can move the ioled.sh script to /usr/bin so you can use it immediately from the SSH command line without having to navigate to your public directory.

here are a couple more scripts to turn on and off your new ioled toy.

#-------ioledon.sh-----------------------------------------------------------------

#!/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

nice -19 ioled.sh&
ps -fl -C “ioled.sh”

#-------------------------------------------------------------------------------------

#-------ioledoff.sh----------------------------------------------------------------

#!/bin/bash
killall bash
killall ioled.sh

#-------------------------------------------------------------------------------------

again you can move these scripts to /usr/bin

remeber to:

chmod 755 ioledon.sh

chmod 755 ioledoff.sh

thus when you SSH into your device… 

To activate the blinking access light you can type

ioledon.sh

To de-activate the access light you can type

 >ioledoff.sh