Created
February 13, 2020 09:18
-
-
Save Matrix7867/3fd36a79ea0a4289aec2fc88c36259ca to your computer and use it in GitHub Desktop.
terminate-gcp-instance-based-on-file-exists-or-not
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
echo "Termination of Instance process will start now" | |
curl -s http://metadata.google.internal/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google" > /home/ubuntu/a | |
touch /home/ubuntu/_SUCCESS | |
filey="/home/ubuntu/_SUCCESS" | |
if [ -f "$filey" ]; then | |
cat /home/ubuntu/a | xargs -I {} gcloud compute instances delete {} --zone=us-central1-a --delete-disks=all --quiet | |
echo "Instance will get terminated" | |
else | |
cat /home/ubuntu/a | xargs -I {} gcloud compute instances stop {} --zone=us-central1-a --quiet | |
echo "Instance will gonna stop" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment