Automated notification of uncommitted git-controlled config changes

Yesterday I wrote about version controlling server configuration with GIT.

Inevitably I will change a file under version control but forget that it is under version control. To mitigate this I’ve thrown together this simple bash script:

#!/bin/bash

CONFIG_REPO="/root/vc"
MAILTO="spam@dev.null"

GIT_CMD="git status --porcelain"

tempfile=`mktemp`

cd "$CONFIG_REPO"
$GIT_CMD > $tempfile

if [ -s $tempfile ]
then
sendmail -oi -t <<EOF
To: $MAILTO
From: $USER@`hostname -f`
Subject: Uncommitted config files detected on `hostname`

I have detected that 'git' believes there are modified and/or added files which have not been committed on `hostname` in '$CONFIG_REPO'.

Hostname: `hostname -f`
Uname: `uname -a`
Repository location: $CONFIG_REPO

Output of '$GIT_CMD':
-----8<-------------------->8-----
`cat $tempfile`
-----8<-------------------->8-----

EOF
fi

rm $tempfile

I’ve put the script in /usr/local/sbin/check-config-git and scheduled it to run daily at midnight via cron. The idea is that if it annoys me every day, as opposed to once a week or even less frequently, I might actually be motivated into doing something about it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>