Skip to content

Instantly share code, notes, and snippets.

@epk2112
Forked from kigawas/watch_and_sync.sh
Created March 25, 2024 16:12
Show Gist options
  • Save epk2112/3a06d7d058b6864ae117606023700f3e to your computer and use it in GitHub Desktop.
Save epk2112/3a06d7d058b6864ae117606023700f3e to your computer and use it in GitHub Desktop.
Automatically rsync local folder to server's folder behind http proxy on Linux
LOCAL=$1 # /home/user/test/
REMOTE=$2 # /home/remoteuser/test/
if [[ -z "$LOCAL" || -z "$REMOTE" ]]; then
echo 'No src/dst folder'
exit
fi
while inotifywait -r -e modify,create,delete $LOCAL; do
rsync -avuz --delete -e "ssh -o \"ProxyCommand=connect-proxy -H YOUR_PROXY_HOST:YOUR_PROXY_PORT %h %p\"" $LOCAL YOUR_USERNAME@YOUR_SERVER_IP:$REMOTE
done
# -avuz means archive mode, verbose output, skip newer files on server, compress
# --delete means if local folder does not have a file "a.txt", then remote folder's file "a.txt" will be deleted if it exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment