New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Howto: Let the LED indicate ongoing backup jobs

A collection of tips on howto tweak your Bubba.
Post Reply
gonk
Posts: 93
Joined: 30 May 2012, 01:53

Howto: Let the LED indicate ongoing backup jobs

Post 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
Gordon
Posts: 1461
Joined: 10 Aug 2011, 03:18

Re: Howto: Let the LED indicate ongoing backup jobs

Post 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
gonk
Posts: 93
Joined: 30 May 2012, 01:53

Re: Howto: Let the LED indicate ongoing backup jobs

Post by gonk »

Thanks Gordon!

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