Created
March 28, 2013 10:58
-
-
Save mjf/5262353 to your computer and use it in GitHub Desktop.
Shell script to detect file or directory has changed using ls, sha1sum, mv and cmp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
checksum=`echo $@ | sha1sum - | cut -d ' ' -f 1` | |
if ! [ -e /tmp/$checksum.ls-ZlaR ] | |
then | |
if ! ls -ZlaR $@ > /tmp/$checksum.ls-ZlaR | |
then | |
echo changed: could not create /tmp/$checksum.ls-ZlaR 1>&2 | |
exit 1 | |
fi | |
fi | |
if ! mv /tmp/$checksum.ls-ZlaR /tmp/$checksum.ls-ZlaR.ref | |
then | |
echo changed: could not rename /tmp/$checksum.ls-ZlaR to /tmp/$checksum.ls-ZlaR.ref 1>&2 | |
exit 1 | |
fi | |
if ! ls -ZlaR $@ > /tmp/$checksum.ls-ZlaR | |
then | |
echo changed: could not create /tmp/$checksum.ls-ZlaR 1>&2 | |
exit 1 | |
fi | |
if cmp -s /tmp/$checksum.ls-ZlaR /tmp/$checksum.ls-ZlaR.ref | |
then | |
exit 0 | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment