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:



GIT_CMD="git status --porcelain"


$GIT_CMD > $tempfile

if [ -s $tempfile ]
sendmail -oi -t <<EOF
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':
`cat $tempfile`


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>