Page 1 of 1

Using md5sum to monitor file diff

Posted: Thu Jul 21, 2011 4:48 pm
by thockman
Here is a quick bash script I wrote to monitor file changes. You can also use incron to watch for directory changes but that is another day.

Code: Select all

#!/bin/bash
# Script: check_diff.sh
# Author: Troy Hockman
# Desc: Checks for md5 diffs.  If no control file it will create one.
# Usage: Set diffpath for directories needed to monitor seperated by spaces
#        Leave the ./check_diff.sh to self check.
#        The first run will create the control.md5.  If you want to restart rm control.md5.
diffpath="./check_diff.sh /etc/"

clear
if [ ! -f "control.md5" ]; then find $diffpath -type f 2>/dev/null -exec md5sum {} \; > control.md5; fi
isfail=$(md5sum -c control.md5 2>/dev/null | grep "FAILED")
if [ "$isfail" ]; then echo $isfail; fi