#!/bin/bash
# http://www.kahealani.com/linux/bin/website_updated
# Released under GNU Lesser General Public License 3:
# http://www.kahealani.com/linux/lgpl-3.0.txt
# by celeste:crystalfaery 2012-02-05 18:53:56+00:00
# The purpose of this script is to generate a difference log for website contents at /var/www
# This depends upon rsnapshots stored at /.snapshots/
# It is expected to be run as a post-process script after rsnapshot runs
# The generated difference file accumulates at /var/www/diff.txt
# The ultimate goal is to produce an RSS feed of website updates.
# Oh, yes, I'm completely insane :-)
# I mean, surely somebody has done better than this already, right?
hostname=tb
cd /.snapshots/hourly.0/$hostname/var/www
nice find . -type f | sed 's/^\.\///' | grep -v "webalizer" | sort > /tmp/website_updated.txt
cd /tmp
echo "# `now`" >> /var/www/diff.txt
for f in `cat /tmp/website_updated.txt`;do
if [ $(diff /.snapshots/hourly.{1,0}/$hostname/var/www/$f 2>/dev/null 1>/dev/null) ]
then
echo '# Changes in '"$f"':'
diff /.snapshots/hourly.{1,0}/$hostname/var/www/$f 2>/dev/null | sed 's/\/\.snapshots\/hourly\.[0-9]\/tb\/var\/www/http:\/\/www.kahealani.com/' >> /var/www/diff.txt
else
touch /var/www/diff.txt
fi
done && rm /tmp/website_updated.txt
syntax highlighted by Code2HTML, v. 0.9.1