1

I have instances in GCP. I can schedule a time to start and stop using the scheduler. But, I don't want a specific time of the day, I want a specific time after instance was started.

For example - Stop the instance after 8 hours the instance is up and running.

EilonA
  • 361
  • 5
  • 17
  • In your startup script, you can execute `sudo shutdown -P +180` for 180 minutes delay (3 hours) – Matthew Dec 16 '21 at 15:20

1 Answers1

1

You can add the contents of a startup script directly to a VM when you create the VM.

You can also pass a Linux startup script directly to an existing VM:

In your Cloud Console go to VM Instance page and click on the instance you want to pass the start up script

  1. Click Edit.

  2. Under Automation, specify the following:

 #! /bin/bash
shutdown -P +60

-P Instructs the system to shut down and then power down.

The time argument specifies when to perform the shutdown operation.

The time can be formatted in different ways:

First, it can be an absolute time in the format hh:mm, where hh is the hour (1 or 2 digits, from 0 to 23) and mm is the minute of the hour (in two digits).

Second, it can be in the format +m, where m is the number of minutes to wait.

Also, the word now is the same as specifying +0; it shuts the system down immediately.

rriovall
  • 406
  • 3
  • 8