Created
July 4, 2013 00:19
-
-
Save keshavsaharia/5923969 to your computer and use it in GitHub Desktop.
A shell script and sample target file to upload to an EC2 instance, which abstracts the tedious scp commands. Be sure to rename "example.target" to the name of your project, i.e. "foo.target". To run it, use "./upload example" to completely rewrite the remote directory, or use "./upload example file.html" to only rewrite a specific file, or use …
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
--- in example.target --- | |
WEB_LOCATION=1.2.3.4 # remote location | |
PEM_LOCATION=example.pem # pem file location | |
DIR_LOCATION=/path/to/your/website # directory location | |
REM_LOCATION=~/htdocs # the directory on the server to write to | |
REM_USER=admin # change to the server's user account name | |
--- in upload --- | |
source $1.target | |
if [ -z $2 ]; then | |
ssh -i $PEM_LOCATION $REM_USER@$WEB_LOCATION "rm -r $REM_LOCATION/*" | |
scp -r -i $PEM_LOCATION $DIR_LOCATION/* $REM_USER@$WEB_LOCATION:$REM_LOCATION | |
elif [ $2 == "file" ]; then | |
scp -r -i $PEM_LOCATION $DIR_LOCATION/$3 $REM_USER@$WEB_LOCATION:$REM_LOCATION/$3 | |
elif [ $2 == "folder" ]; then | |
scp -r -i $PEM_LOCATION $DIR_LOCATION/$3/* $REM_USER@$WEB_LOCATION:$REM_LOCATION/$3 | |
elif [ -d "$DIR_LOCATION/$2" ]; then | |
scp -r -i $PEM_LOCATION $DIR_LOCATION/$2/* $REM_USER@$WEB_LOCATION:$REM_LOCATION/$2 | |
elif [ -f "$DIR_LOCATION/$2" ]; then | |
scp -r -i $PEM_LOCATION $DIR_LOCATION/$2 $REM_USER@$WEB_LOCATION:$REM_LOCATION/$2 | |
else | |
echo "Invalid parameter." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment