Last active
September 11, 2020 19:23
-
-
Save pydevops/9000e2aed5346ede351b9df36df31b42 to your computer and use it in GitHub Desktop.
gcp start stop tagged instance script for cost saving
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 | |
set -euo pipefail | |
start_stop() { | |
while read name zone ; do | |
echo "$name with $zone" | |
gcloud compute instances $CMD $name --zone $zone & | |
done < <(gcloud compute instances list --filter='tags.items~^stoppable$' --format='value(NAME,ZONE)') | |
wait | |
gcloud compute instances list --filter=running | |
echo "$CMD are done!" | |
} | |
CMD=$1 | |
gcloud compute instances list --filter=running | |
read -p "Do you want to proceed?" yn | |
case $yn in | |
[Yy]* ) start_stop;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment