Skip to content

Instantly share code, notes, and snippets.

@brightredchilli
Created December 7, 2017 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brightredchilli/f912d87977399ccdace8041fd2812db4 to your computer and use it in GitHub Desktop.
Save brightredchilli/f912d87977399ccdace8041fd2812db4 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This script is made to run inside a docker container, when we need to watch for changes in the container and build.
# Initially used for watching changes and doing a Hugo build, but this should be pretty general purpose.
# We simply calculate the md5sum of the entire directory every second, and trigger the build command if something has changed
PREV_VALUE=""
while :
do
VALUE=`tar --exclude="dir/to/exclude" --exclude="anotherdir/to/exclude" -cf - . | md5sum`
if [ "$VALUE" != "$PREV_VALUE" ]; then
./command_to_run # or the script to run
fi
PREV_VALUE=$VALUE
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment