Skip to content

Instantly share code, notes, and snippets.

@elhardoum
Created January 19, 2020 13:51
Show Gist options
  • Save elhardoum/e709c63021b73357d7877b465d7075d4 to your computer and use it in GitHub Desktop.
Save elhardoum/e709c63021b73357d7877b465d7075d4 to your computer and use it in GitHub Desktop.
Live sync of your local project with a remote using rsync and monitoring file changes
#!/usr/bin/env sh
function syncfunc(){
[ -f ./livesync.lock ] && exit -1
touch /tmp/livesync.lock
command -v say > /dev/null && say synchronizing || echo synchronizing
rsync -r -a -v -e "ssh -p22" --delete ./ user@host-or-ip:/path/to/remote/folder/eg/root/project1
command -v say > /dev/null && say synchronized || echo synchronized
rm -f /tmp/livesync.lock
}
export -f syncfunc
while true; do
touch ./.livesync-lastwatch
sleep 2
find . -cnewer ./.livesync-lastwatch -exec bash -c 'syncfunc' \;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment