gcloudcommand to delete itself. This script needs to be provided in a file or at an available URL when launching the instance.
3600svalue on the second line), then look up information about the running instance and put it in shell variables (the third and fourth lines), and finally run a
gcloudcommand to delete itself.
3600swith a different value. A number, or a number followed by an
s, stands for that number of seconds. You can specify a duration in minutes, hours, or days, by using the suffix
din place of
sleep 3600sline with one or more commands to install, configure, and run the program you want.
startup.shfile created in the previous section is such a program.
#!, as they are here, the Linux environment will run the program named, providing the file as its input. So, Linux will invoke
/bin/sh, the Bourne shell, to run this file. You may be familiar with [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) in the terminal window for Linux and Mac machines. The Bourne shell is an earlier, similar program for running commands.
sleepprogram, which does nothing but wait the specified time before it exits, which introduces a delay of an hour (3600 seconds) before the next commands are run.
ZONE). These variables are used in a later command. The
$(command)portion runs the command in the parentheses and returns the output of that command as its value. The commands here are each
curlcommands that make web requests and output the responses to the requests.
https: because there is no actual network activity, there is no need for a secure network connection.
--quietoption indicates that the command should not ask for user confirmation of an action, because it runs in batch mode with no user available. The
compute instancescommand group performs operations on Compute Engine instances. The
deletecommand completely removes an instance. The instance
ZONEvariables in the command specify which instance to delete. You can replace
stopto stop the instance so that it can be restarted later.
myinstancein this command with your instance name.
startup.shfile that you created in the "Preparation" section early in this tutorial.
Yfor yes if needed.
--metadata-from-file=startup-script=startup.shoption specifies that the new instance's metadata-server should provide the contents of the
startup.shfile as the value of
startup-scriptwhen the instance requests it. For standard Compute Engine instances, that will cause the instance to run that script when it starts.
--scopes=compute-rwoption specifies that the instance should have permission to use all Compute Engine APIs, including the API to delete an instance. By default, new instances do not have that privilege, so it needs to be added here so it can delete itself.