-
-
Save scjody/2febd362436ae33bab78aca891324289 to your computer and use it in GitHub Desktop.
"gcloud compute scp" wrapper to figure out the zone automatically
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
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 "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.