-
-
Save tahaozket/b0b80e573f689603da028afbad75a88d to your computer and use it in GitHub Desktop.
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
# install parallel first (sudo apt-get install -y parallel) | |
JOB_NUM=10 | |
NAME_FILTER='*' | |
# stop instances | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/RUNNING/ {printf "gcloud -q compute instances stop %s --zone %s;\n", $1, $2 > "stop-instances.txt" }' | |
parallel --jobs $JOB_NUM < stop-instances.txt | |
# remove delete protection | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/TERMINATED/ {printf "gcloud -q compute instances update %s --no-deletion-protection --zone %s;\n", $1, $2 > "remove-protection.txt" }' | |
parallel --jobs $JOB_NUM < remove-protection.txt | |
# delete instances | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/TERMINATED/ {printf "gcloud -q compute instances delete %s --zone %s;\n", $1, $2 > "delete-instances.txt" }' | |
parallel --jobs $JOB_NUM < delete-instances.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment