Page 1 of 1

Howto: Let the LED indicate ongoing backup jobs

Posted: 03 Mar 2013, 06:54
by gonk
I just hacked this simple solution to let the LED indicate if a backup job, either duplicity or rsync, is executing or not.

If you find it useful, use it, share it and maybe reply to this thread.
If you find room for improvement please post your version below.
If you have suggestions or questions... guess what to do.

/home/whatever_user/bin/led_color.sh

Code: Select all

#!/bin/bash

if (( `ps axu|egrep "duplicity|rsync"|grep -v egrep|grep -v daemon|wc -l` >0)); then echo "1";else echo "0";fi > /sys/bus/platform/devices/bubbatwo/color
In /etc/crontab

Code: Select all

#LED
#----------
# m     h  dom mon dow  user    command
*/1     *  *   *   *    root    /home/whatever_user/bin/led_color.sh

Re: Howto: Let the LED indicate ongoing backup jobs

Posted: 25 Aug 2013, 05:31
by Gordon
Since the command you're running is a one-liner, why not put that one-liner directly i a cron file (I'd choose a separate file in /etc/cron.d rather than changing crontab directly).

Also you can search for specific process directly with `ps` using the -C option:

Code: Select all

ps -C duplicity,rsync
...and you can also tell `grep` to return the number of hits (which you can restrict to a maximum) rather than a string that contains the needle. Combining this you can write a command that will return either 1 or 0, depending on the existence of (any of) the searched for process(es):

Code: Select all

# for processes owned by root only
ps -C duplicity,rsync -f | grep -m 1 -c "^root"

# or if you want to include non root owned processes
ps -C duplicity,rsync -f --no-header| grep -m 1 -c .

The resulting cron file in /etc/cron.d thus looks as follows:

Code: Select all

#LED
#----------
# m     h  dom mon dow  user    command
*/1     *  *   *   *    root    echo $(ps -C duplicity,rsync -f | grep -m 1 -c "^root") > /sys/bus/platform/devices/bubbatwo/color

Re: Howto: Let the LED indicate ongoing backup jobs

Posted: 26 Aug 2013, 09:19
by gonk
Thanks Gordon!

That's the kind of great collaborative work aimed at contributing and helping each others.