Skip to content

Instantly share code, notes, and snippets.

@jdavidbakr
Last active August 29, 2015 14:21
Show Gist options
  • Save jdavidbakr/4f5005513f46bddbc00d to your computer and use it in GitHub Desktop.
Save jdavidbakr/4f5005513f46bddbc00d to your computer and use it in GitHub Desktop.
Script: Watch & Upload Directory
#!/bin/bash
LOCAL_PATH=$1
REMOTE_SERVER=$2
REMOTE_PATH=$3
CHANGED_FILE=$4
echo Changed File: $CHANGED_FILE
FILE=`echo $CHANGED_FILE | sed 's|'$LOCAL_PATH'/||'`
if [ -e $CHANGED_FILE ]
then
rsync -av --exclude storage --exclude .git $LOCAL_PATH/$FILE $REMOTE_SERVER:$REMOTE_PATH/$FILE
else
rsync -av --delete --exclude .git --exclude storage $LOCAL_PATH/ $REMOTE_SERVER:$REMOTE_PATH
fi
#!/bin/bash
# Watches a directory and calls ~/bin/sync-remote to sync any local changes to a remote server.
# Requires fswatch: https://github.com/emcrisostomo/fswatch
# Two arguments
if [ "$#" -ne 3 ];
then
echo
echo "Usage: watch-dir [local-path] [remote-server] [remote-path]"
echo "Use the full path for the local directory"
echo
exit
fi
LOCAL=$1
REMOTE=$2
REMOTE_PATH=$3
# Initially make sure we're synced
rsync -av --exclude .git --exclude storage $LOCAL/ $REMOTE:$REMOTE_PATH
# Now watch for changes
echo
echo "Watching $LOCAL for changes."
echo
fswatch -e '.git' $LOCAL | xargs -n1 ~/bin/sync-remote $LOCAL $REMOTE $REMOTE_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment