Skip to content

Instantly share code, notes, and snippets.

@seancheung
Created November 8, 2017 07:45
Show Gist options
  • Save seancheung/a46df89ba5d0646aa04a50f07556ebd1 to your computer and use it in GitHub Desktop.
Save seancheung/a46df89ba5d0646aa04a50f07556ebd1 to your computer and use it in GitHub Desktop.
copy to multiple servers with scp
#!/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