Skip to content

Instantly share code, notes, and snippets.

@asjadathick
Created March 17, 2020 02:51
Show Gist options
  • Select an option

  • Save asjadathick/0b1fff5968217107d9bc76b072d73a14 to your computer and use it in GitHub Desktop.

Select an option

Save asjadathick/0b1fff5968217107d9bc76b072d73a14 to your computer and use it in GitHub Desktop.
Stop all gcloud compute instances with a prefixed name
#!/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