Senpiper Technologies Devops Internship Assignment: ("%H %L %U %T "%R" % S %B "% (Referer) I" "% (User-Agent) I")
Senpiper Technologies Devops Internship Assignment: ("%H %L %U %T "%R" % S %B "% (Referer) I" "% (User-Agent) I")
ASSIGNMENT
Question 1 - Find the count of log statements in the attached file “access.log”
with successful response (status code 200)?
“The successful response log statements with status code 200 are – 18
(HTTP/1.1 = 16 and HTTP/1.0 = 2)”
It is possible that the string 200 will occur elsewhere in log file. So, we should
ensure that we only match HTTP success code. So that –
Command:
Or:
We can also find HTTP status 200 using “awk” command but for that log
should be in same format (In access.log file, logs aren’t in same format.)
If logs modified in ["%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-
agent}i"] this format, This command will find the HTTP status which match
with 200 status.)
-----------------------------------------------------------------------------------------------------
Question 2 - Write command to find the filenames containing words DEBUG,
ERROR, and INFO in any directory of the filesystem.
Answer –
This will check whole Linux filesystem for the given words (sensitive) and
return filename with relative path (It also return that filename, whose name
contains these words in prefix or suffix) –
Command –
-----------------------------------------------------------------------------------------------------
Question 3 - What would be the sed command to convert the string input
"Ab1Cd2Ef3Gh4Ij5….." to "abcdefghij…."?
Answer –
First remove numerical Integers from string and then convert the string to
required string by changing that in lower case –
Command –
-----------------------------------------------------------------------------------------------------
Question 4 - Write a shell/python script/program to return true if the opening
and closing braces are complete, otherwise false.
#!/usr/bin/python3
def BalancedBrackets(Str):
# stack for storing opening brackets
stack = []
return True
Command: ./check-parenthesis.py
https://colab.research.google.com/drive/1LJTGisr9u5bOiOuUKUorOMehItty
dQWD?usp=sharing
-----------------------------------------------------------------------------------------------------
Question 5 - Write steps to create and publish a Docker image to the Docker
repository.
a. Creating an “index.html” file and inserting some html which will be shown
on the homepage (use :wq to exit) –
<!DOCTYPE html>
<html>
<head>
<title>Assignment</title>
</head>
<body>
<h1>This is the Assignment for the DevOps role.</h1>
<p> You are hitting a container </p>
</body>
</html>
b. Creating Dockerfile through vi editor and insert data (for save and exit : esc
-> :wq) –
Data:
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["apache2ctl","-D","FOREGROUND"]
c. Building Docker image from Dockerfile –
# Now, Push this image to docker hub (docker image name should be same
as docker repository)
http://<host-ip>:80
a. First, We pull the latest image of Ubuntu and create container from it –
Html Command:
<!DOCTYPE html>
<html>
<head>
<title>Assignment</title>
</head>
<body>
<h1>This is the Assignment for the DevOps role.</h1>
<p> You are hitting a container </p>
</body>
</html>
f. Now, here, we have container in which apache server is installed and our
page is configured. Now, create a customized Docker image from this
container –
# Now, Push this image to docker hub (docker image name should be same
as docker repository)
http://<host-ip>:80
-----------------------------------------------------------------------------------------------------
server {
listen 80 default_server;
root /var/www/html;
} Write a location block for requests “/api” that will serve the requests from
backend controller “/welcome/home”.
Answer:
Server {
listen 80 default_server;
root /var/www/html;
location /api {
root /welcome/home;