Last active
May 10, 2017 17:49
-
-
Save renie/9fb4c5d06ed3f6fea7761e967c1d5c3e to your computer and use it in GitHub Desktop.
This file contains 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 | |
##### | |
# IMPORTANT! | |
# - Install rsync and inotify-tools | |
# - For better usage, config your ssh conections and keys | |
##### | |
if [ $# -lt 3 ]; then | |
echo "An origin path, a destination path and a user@server must be set (in this order)." | |
exit 1 | |
fi | |
origin="$1" | |
destination="$2" | |
remote="$3" | |
if [ ! -d "$origin" ]; then | |
echo "Invalid origin path." | |
exit 1 | |
fi | |
if ssh -p 22 -tt $remote "test ! -d $destination"; then | |
echo "Destination path does not exists or it is unavailable." | |
exit 1 | |
fi | |
while true; do | |
inotifywait -r -e "CREATE,CLOSE_WRITE,DELETE,MODIFY,MOVED_FROM,MOVED_TO" $origin | |
rsync -Cravz --delete $origin $remote:$detination | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment