Created
March 17, 2020 02:51
-
-
Save asjadathick/0b1fff5968217107d9bc76b072d73a14 to your computer and use it in GitHub Desktop.
Stop all gcloud compute instances with a prefixed name
This file contains hidden or 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 | |
| INSTANCE_PREFIX="asjad" | |
| read -r -p "Stop all instances with prefix $INSTANCE_PREFIX? [y/N] " response | |
| response=`echo "print('$response'.lower())" | python` | |
| if [[ "$response" =~ ^(yes|y)$ ]] | |
| then | |
| for i in `gcloud compute instances list --filter $INSTANCE_PREFIX | awk '{print $1}' | sed 1,1d`; do gcloud compute instances stop "$i"; done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment