Generate and Validate MD5 of a folder
  • The following bash script generates MD5 hash for a folder using the Unix find command
#!/bin/bash
# gen.sh
CRCFILE=allcrc.md5
echo $CRCFILE
chmod u+rwx $CRCFILE
find /path/to/html -type f -exec /usr/bin/md5sum {} \; > $CRCFILE
#find ../html -type f -exec /usr/bin/md5sum {} \; > $CRCFILE
chmod go-rwx $CRCFILE
chmod u-wx $CRCFILE
  • The following bash script validates the MD5 hash for the same folder, the intention of this is to be run from cron
#!/bin/bash
# check.sh
CRCFILE=allcrc.md5
echo $CRCFILE
LINES=`/usr/bin/md5sum -c $CRCFILE | grep -v OK`
echo $LINES

If run from cron with a MAILTO option, then whenever it is run, it will email results.

MAILTO="user@mydomain.com"
# 1 Daily_CRC_Check
50 1 * * * /path/to/check.sh
genmd5.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0