Skip to content

Instantly share code, notes, and snippets.

@scjody
Last active December 7, 2018 15:15
Show Gist options
  • Save scjody/2febd362436ae33bab78aca891324289 to your computer and use it in GitHub Desktop.
Save scjody/2febd362436ae33bab78aca891324289 to your computer and use it in GitHub Desktop.
"gcloud compute scp" wrapper to figure out the zone automatically
function gscp {
gcloud config list |grep 'Your active'
for arg in "$@"; do
if echo "$arg" | grep -q : - ; then
break
fi
done
INST=$(echo "$arg" | cut -f1 -d:)
ZONE=$(gcloud compute instances list |grep --colour=none -E "^$INST[[:space:]]" | awk '{print $2}')
echo zone: $ZONE
gcloud compute scp --zone=$ZONE "$@"
}
@scjody
Copy link
Author

scjody commented Feb 5, 2018

Put this in your path and you'll be able to scp to/from an instance without figuring out its zone in advance:
gscp somefile jody-imageserver-test:
gscp jody-imageserver-test:somefile .

If you use multiple configurations (gcloud config) to deal with more than one project, you'll need to be sure you've selected the correct configuration. This wrapper makes that easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment