• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

GCP Start Multiple Instances

January 19, 2020

Here’s how to start multiple instances using Bash and Google SDK.

#!/bin/bash
while IFS=', ' read -r a b c; do
  instance="${a//[[:blank:]]/}"
  project="${b//[[:blank:]]/}"
  zone="${c//[[:blank:]]/}"
  echo "Starting $instance ...."
  gcloud compute instances start $instance \
  --zone $zone --project $project --async
done < instance-list.txt

#!/bin/bash while IFS=', ' read -r a b c; do instance="${a//[[:blank:]]/}" project="${b//[[:blank:]]/}" zone="${c//[[:blank:]]/}" echo "Starting $instance ...." gcloud compute instances start $instance \ --zone $zone --project $project --async done < instance-list.txt

Instances are read from an external file. The file format is displayed below.

server1,project1,us-central1-a
server2,project2,us-central1-b
server3,project3,us-central1-c

server1,project1,us-central1-a server2,project2,us-central1-b server3,project3,us-central1-c

To stop multiple instances, replace “start” with “stop.”

Filed Under: Cloud Tagged With: compute, gcloud, instances, multiple, sdk, start, stop

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023