BRON: Sample Scripts

Here’s some sample scripts. Note that I’m no master scriptor, these aren’t the greatest scripts ever, but they work for me…

(note too, the lines below may be wrapped for display, but should not wrap if you use them.)

This is how I backup my documents:

# filename:
#. /accounts/1000/shared/misc/bron/conf/env-vars.txt
export APPDIR=/accounts/1000/shared/misc/bron
export myName=`basename $0 .sh` # resolves to backup-shared-documents
export SRCDIR=/accounts/1000/shared/documents
export DESTDIR=/accounts/1000/shared/misc/SDCARD/misc/backup #note: SDCARD is a symlink I created to /accounts/1000/removable/sdcard
export verbose=0

# if verbose is set, use -VRn to cp command
# if not set, just do -vRn
if [[ $verbose -eq 1 ]]; then
        print "verbose is on"
        echo "starting backup at `date`" > $APPDIR/logs/$myName.log
        echo "-> ignoring skipped files.." >> $APPDIR/logs/$myName.log
        cp -VRn $SRCDIR $DESTDIR 2>&1 >> $APPDIR/logs/$myName.log #note: the -V turns on EXTRA verbose messages
        echo "backup ended at `date`" >> $APPDIR/logs/$myName.log
        print "verbose is not on"
        echo "starting backup at `date`" > $APPDIR/logs/$myName.log
        cp -vRn $SRCDIR $DESTDIR 2>&1 >> $APPDIR/logs/$myName.log #note: the -v turns on verbose messages, but not as verbose as -V
        echo "backup ended at `date`" >> $APPDIR/logs/$myName.log

This is how I check flash usage. this script creates a Notification if flash usage is over 60%.

# filename:
. /accounts/1000/shared/documents/env-vars.txt
export myName=`basename $0 .sh` #resolves to check-flash-usage

# check a filesystem to see if it exceeds a threshold
warning=`df -h |gawk -f $BRONDIR/scripts/get-flash-usage.awk -v threshold=60`
echo "starting flash check at `date`" > $BRONDIR/logs/$myName.log
if [[ -z $warning ]]; then   # if $warning is empty, then
        echo "warning is empty!"
        echo "flash usage is ok" >> $BRONDIR/logs/$myName.log
        echo "warning is NOT empty!"
        echo "$warning" > $BRONDIR/alerts/$myName.notification
echo "ending flash check at `date`" >> $BRONDIR/logs/$myName.log

..and here’s the awk script that it calls as well…

# note: I'm not great with awk, but it works
# note: the variable $threshold is set when gawk is called by passing "-v threshold=60". see the script above
        if ($1 ~ /user0/) {
                i = split($5, num, "")
                if (i > 2) {
                } else {
                if (usage > $threshold){
                        print "Warning: flash (", $1, ") is over threshold! (threshold: ", threshold, ", value: ", $5, ")." 
%d bloggers like this: