0
0
GCPcloud~10 mins

Startup scripts for automation in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a startup script to a Compute Engine instance metadata.

GCP
gcloud compute instances add-metadata my-instance --metadata startup-script=[1]
Drag options to blanks, or click blank then click option'
A"#!/bin/sh echo Startup script running"
B"#!/bin/bash echo Hello World"
C"#!/bin/bash echo Hello from startup script"
D"#!/bin/bash echo Instance started"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the script string
Using incorrect shell syntax
2fill in blank
medium

Complete the code to create a VM instance with a startup script that updates packages.

GCP
gcloud compute instances create my-vm --metadata startup-script=[1]
Drag options to blanks, or click blank then click option'
A"#!/bin/bash sudo apt-get update -y"
B"#!/bin/bash sudo yum update -y"
C"#!/bin/bash sudo pacman -Syu --noconfirm"
D"#!/bin/bash sudo zypper refresh"
Attempts:
3 left
💡 Hint
Common Mistakes
Using package managers not available on the OS
Omitting sudo for commands requiring root
3fill in blank
hard

Fix the error in the startup script metadata to correctly run a script that installs nginx.

GCP
gcloud compute instances add-metadata web-server --metadata startup-script=[1]
Drag options to blanks, or click blank then click option'
A"#!/bin/bash sudo apt-get install -y nginx"
B"#!/bin/bash sudo apt-get install nginx"
C"#!/bin/bash sudo install nginx -y"
D"#!/bin/bash sudo apt-get install nginx -y"
Attempts:
3 left
💡 Hint
Common Mistakes
Placing -y after the package name
Using incorrect install commands
4fill in blank
hard

Fill both blanks to write a startup script that creates a file and writes text into it.

GCP
#!/bin/bash
echo [1] > /tmp/startup.txt
chmod [2] /tmp/startup.txt
Drag options to blanks, or click blank then click option'
A"Hello from startup script"
B755
C644
D"Startup script ran successfully"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect permission numbers
Forgetting to quote the text string
5fill in blank
hard

Fill all three blanks to create a startup script that updates packages, installs nginx, and starts the service.

GCP
#!/bin/bash
sudo [1] update -y
sudo [2] install -y nginx
sudo systemctl [3] nginx
Drag options to blanks, or click blank then click option'
Aapt-get
Byum
Cstart
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing package managers
Using systemctl stop instead of start