Skip to content

Instantly share code, notes, and snippets.

@eduo
Created May 8, 2020 13:03
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 eduo/b415217fa1f911f70e38442ab899502c to your computer and use it in GitHub Desktop.
Save eduo/b415217fa1f911f70e38442ab899502c to your computer and use it in GitHub Desktop.
OSX Bash Script to synchronise remote folder when changes are detected. Requires fswatch (homebrew)
#!/bin/bash
#
run_rsync_acc () {
RSYNC_COMMAND=$(rsync -azPim --delete-before --no-motd --exclude ".*/" --exclude=.DS_Store ~/rootfolder/ remoteuser@remotesite.com:remotelocation)
if [ $? -eq 0 ]; then
# Success do some more work!
if [ -n "${RSYNC_COMMAND}" ]; then
# Stuff to run, because rsync has changes
echo "Sincronized: "
# echo $?
# osascript -e 'display notification "Updated remote" sound name "Tink"'
osascript -e 'display notification "Updated remote"'
# else
#echo "NO changes"
# No changes were made by rsync
fi
else
# Something went wrong!
echo "Error! Something went wrong!"
exit 1
fi
}
run_rsync_acc
fswatch -o ~eduo/rootfolder | while read f
do date
run_rsync_acc
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment