Last active
August 29, 2015 14:21
-
-
Save jdavidbakr/4f5005513f46bddbc00d to your computer and use it in GitHub Desktop.
Script: Watch & Upload Directory
This file contains hidden or 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 | |
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 |
This file contains hidden or 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 | |
# 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