Created
November 8, 2017 07:45
-
-
Save seancheung/a46df89ba5d0646aa04a50f07556ebd1 to your computer and use it in GitHub Desktop.
copy to multiple servers with scp
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 | |
USERNAME=username | |
WORK_DIR=/path/to/workdir | |
declare -a HOSTS=("hostname1" "hostname2" "hostname3") | |
function copy_files() | |
{ | |
scp -r "$WORK_DIR" "$USERNAME"@"$1":"$WORK_DIR" | |
} | |
function install_deps() | |
{ | |
if [ -n "$1" ]; then | |
ssh "$USERNAME"@"$1" "cd ${WORK_DIR} && npm i --production" | |
else | |
cd "$WORK_DIR" | |
npm i --production | |
fi | |
} | |
for i in "${HOSTS[@]}" | |
do | |
copy_files "$i" | |
install_deps "$i" | |
done | |
install_deps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment