Archive for May, 2010

But Mine Will Be Round Part the 318th

Friday, May 28th, 2010

Since I’m finally getting down to grinding through my email I thought “wouldn’t it be cool to see visible evidence of my progress?” Then after I’d procrastinated for quite a while on the munin plugin repository looking at many plugins which were almost but not quite what I wanted, I decided to cement my stalling by writing my own. I even took the time to make it a wildcard plugin, though it is highly tailored to my email setup. (In short, it uses Maildir structure and my mailboxes tend to have a goofy set of period-delimited names where only the suffix is material.)


#!/bin/bash

# mailbox_ by Shannon Prickett <binder@manjusri.org>

MAILUSER=${0##*mailbox_}

case $1 in
    config)
        cat << 'EOT'
graph_title Emails By Folder
graph_vlabel Emails
graph_category mail
graph_args --base 1000 -l 0
graph_scale no
graph_info The count of emails in the current and new email folders.
EOT
        ;;
esac

TARGET="/home/${MAILUSER}/Maildir"
for folder in `ls -a ${TARGET}`
do
    if [ -d ${TARGET}/$folder/cur ]; then
        SHORTNAME=$(echo ${folder} | cut -d. -f 3 -)
        if [ -z ${SHORTNAME} ]; then
            SHORTNAME=INBOX
        fi
        case $1 in
            config)
                echo "${SHORTNAME}.label ${SHORTNAME}"
                ;;
            *)
                CURCOUNT=$(ls ${TARGET}/$folder/cur | wc -l)
                NEWCOUNT=$(ls ${TARGET}/$folder/new | wc -l)
                COUNT=$((${CURCOUNT}+${NEWCOUNT}))
                echo "${SHORTNAME}.value ${COUNT}"
                ;;
        esac
    fi
done

UPDATED: now it sums read and unread and has a typo fixed.

Overengineering is Bestengineering

Thursday, May 27th, 2010

As you may know, I’m a big fan of what I’d consider the JWZ PSA style of data backup for my home systems (none of them are really pretentious enough to even be considered servers). For a while I’ve been continuing to expand on the list of –exclude options I’d been passing to rsync. But no more! At long last my tolerance for rambling rsync options was exhausted.

So of course I turned it into a script. This script.


#!/bin/bash

EXCLUDES=`mktemp --tmpdir=/tmp rsyncex.XXXXXX`
RSYNCFLAGS="-q"

while getopts "v" Option
do
    case $Option in
    v   )   RSYNCFLAGS='-v';;
    *   )   echo "Only know -v for verbose" ;;
    esac
done
        
(
cat <<'EOL'
*.lock
/proc/*
/sys/*
*/tiger/work/*
*/nagios3/spool/*
tmp/*
/tmp/*
/opt/splunk/var/*
/var/www/munin/*
EOL
) > ${EXCLUDES}

# as an idle job if you can
/usr/bin/ionice -c 3 -t \
    /usr/bin/rsync -xa ${RSYNCFLAGS} --links \
        --exclude-from=${EXCLUDES}  --delete / /mnt/backup

rm ${EXCLUDES}

The points at which you would want to modify it for your own use should be obvious, if not the point of why you would want to use it at all.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...