Skip to content

Instantly share code, notes, and snippets.

@douglascodes
Last active July 5, 2017 11:21
Show Gist options
  • Save douglascodes/90e3d0e331ec8fe739960c0e3156d63c to your computer and use it in GitHub Desktop.
Save douglascodes/90e3d0e331ec8fe739960c0e3156d63c to your computer and use it in GitHub Desktop.
Script to update web directory on change. A -> B Watch using inotifywait.
#!/bin/sh
# Syncs files from directory A to B. With the 'chown' this will need to be run as root.
# Drop that to run as unprivileged user.
if [ $# -lt 2 ] ; then
echo "usage: $0 <dir to watch> <sync to>"
fi
source="$1"
destination="$2"
echo "Watching: ${source}"
echo "Destination: ${destination}"
while /usr/bin/inotifywait -r -e delete,move,modify "${source}" --exclude ".idea"
do
# Change to http user. Delete missing. Ignore jetbrains directories. Ignore git/cvs/sub. Recursive
/usr/bin/rsync --chown=http:http --delete --exclude=".idea" -C -rv -- ${source}/* ${destination}/;
done
@douglascodes
Copy link
Author

The inotifywait package is usually called inotify-tools. Binary paths are from Arch, adjust as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment