Lab‐10 - LPouliot/Senior-Fall-CSI-230-SYS-320-03-Automation-and-Scripting GitHub Wiki

Ubuntu Apache Logs

Creating Ubuntu Apache Logs:

Steps:

  • Update Ubtunu
  • Install Apaceh2
  • Start Apache2
  • Check Status
  • Get IP address and take note

10.0.17.24

  • Open a web browser via IP address to verify

Deliverable-1: Screenshot similar to the one above, showing access to the default apache2 page (with IP address showing at URL).

Let's create a few pages. Remove the default index.html in /var/www/html and create your own index.html with the following content:

Index.html:

page1.html

page2.html

Browse through your pages from your web browser by clicking on the links a few times (this will create logs):

Install curl

Access to your web page using curl

Create a script called basic_access_intruder.bash that will access to the web page 20 times in a row:

Create the basic_access_intruder.bash file in week11 directory of your working directory

  1. It will have a for loop that will execute 20 times.

  2. In your for loop, call curl (from the screenshot above but with your ip address)

Deliverable-2: Share screenshot of the contents of your basic_access_intruder.bash and screenshot of it running like one below:

Accessing Ubuntu Apache Logs:

Your Apache logs will be under /var/log/apache2/

You can use cat, tail, head and similar terminal commands to obtain the contents of a file

You can use grep, awk and similar commands to filter the contents of a file

The following script separates the lines (cuts) by space (' ') and only displays 1st and 4th. trim (tr) by delimeter "[" gets rid of the character "["

Deliverable-3: Utilizing a series of pipes (using "|") with cut, grep, and trim to display only IP address and page name, for records that indicate access to page2.html. Share a screenshot of the contents of your bash file and a screenshot of your script running the one below (but for page2.html):

Function Processing Ubuntu Apache Logs:

You can create functions to access content in specific ways

You can further process the results of one function by using echo on the variable where the results are saved:

Deliverable-4: Create a function that is called pageCount. This function will return how many times each page was accessed. Share a screenshot of your script. Share a screenshot of your script running like the one below:

Hint: You can list only the pages accessed. Then research what "sort, and uniq" commands do in bash.