Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I JUST NEED ANSWER OF STOP 5 I HAVE DONE SCRIPT TILL STEP 4 POSTED BELOW PELASE ADD THE STEP 5 IN THE SCRIPT SCRIPT

I JUST NEED ANSWER OF STOP 5 I HAVE DONE SCRIPT TILL STEP 4 POSTED BELOW PELASE ADD THE STEP 5 IN THE SCRIPT

SCRIPT AND QUESTION BELOW

(Bash Question-Create a script in bash which achieve the following tasks ) For these instructions hosting VM means the VM your script runs on and container means the Ubuntu container named COMP2101-S22 running inside your hosting VM.

1.On the hosting VM, install lxd if necessary, do not install lxc-utils

2.On the hosting VM, run lxd init --auto if no lxdbr0 interface exists

3.On the hosting VM, launch a container running Ubuntu 20.04 server named COMP2101-S22 if necessary

4.On the hosting VM, add or update the entry in /etc/hosts for hostname COMP2101-S22 with the containers current IP address if necessary

5.On the hosting VM, install Apache2 in the container if necessary

SCRIPT

#!/bin/bash # Define variables CONTAINER_NAME=COMP2101-S22 # Install required packages if not already installed sudo apt install -y curl # Install lxd if not already installed if ! command -v lxd >/dev/null; then echo "Installing lxd..." sudo snap install lxd echo "lxd has been installed." fi # Run lxd init if lxdbr0 interface doesn't exist if ! ip a show lxdbr0 >/dev/null; then echo "No lxdbr0 interface found, running lxd init..." sudo lxd init --auto echo "lxd init has completed." fi # Launch COMP2101-S22 container if it doesn't exist if ! sudo lxc list | grep -q $CONTAINER_NAME; then echo "$CONTAINER_NAME container not found, launching..." sudo lxc launch ubuntu:20.04 $CONTAINER_NAME echo "$CONTAINER_NAME container has been launched." fi # Get the container's IP address container_ip=$(sudo lxc list | grep $CONTAINER_NAME | awk '{print $6}') # Add or update the /etc/hosts entry for COMP2101-S22 if ! grep -q $CONTAINER_NAME /etc/hosts || ! grep -q $container_ip /etc/hosts; then echo "Updating /etc/hosts entry for $CONTAINER_NAME container..." sudo sed -i "/$CONTAINER_NAME/d" /etc/hosts echo "$container_ip $CONTAINER_NAME" | sudo tee -a /etc/hosts > /dev/null echo "/etc/hosts entry for $CONTAINER_NAME container has been updated." fi #STEP 5 HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

Describe four different approaches to retaining staff.

Answered: 1 week ago