Last active
August 29, 2015 14:07
-
-
Save mitchellrj/55d0d8790f51503e8984 to your computer and use it in GitHub Desktop.
Script to watch a file for modifications and revert it immediately
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/bash | |
# | |
# Usage: watch-and-revert.sh filename | |
# | |
BACKUP="$(dirname $1)/.backup-$(basename $1)" | |
function cleanup { | |
rm $BACKUP | |
} | |
trap cleanup EXIT | |
cat $1 > $BACKUP | |
while true; do | |
inotifywait -qo /dev/null -e close_write $1 | |
cat $BACKUP > $1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment