Question: Your assignment is to write a shell script named astats.sh. The script reports and prints selected information gleaned from the Apache web server logs. Again,
Your assignment is to write a shell script named astats.sh. The script reports and prints selected information gleaned from the Apache web server logs. Again, I will describe the action of this shell script by first showing the help information:
Usage: ./astats.sh
Reports selected information about Apache. If no filename is given, we use /home/ruizhao/CYBR3350/HW4/access_log
Request:
-h Print this long message
IPs print a sorted list of all unique IP addresses that have accessed the server, and a total count at the end
Users print all unique user names whose web pages have been accessed, and a total count at the end
So for example: ./astats.sh IPs will examine /home/ruizhao/CYBR3350/HW4/access_log and provide a sorted list of all unique IP accesses, and at the end of the list will also print the total number of unique IP addresses.
An entry in the log file looks like this (it is really all in one line):
174.71.76.52 - - [01/Dec/2016:17:22:34 -0600] "GET /~csymons/project/css/normalize.css HTTP/1.1" 304 -
So if you want to break this up in a program written in awk, say, or cut, the IP address is $1 (174.71.76.52), the date is $4 (01/Dec/2016), and so on. Also, the user can be determined by the part a few characters after the GET request in the above example the user is csymons. If the GET request is just for / then theres no user. For example:
41.141.165.6 - - [01/Dec/2013:18:40:11 -0600] "GET / HTTP/1.1" 200 6819
Hints:
Want just the filename from a record? cat access_log | cut '-d ' -f7
Want to sort by IP address? Do a google search on Lars Michelsen sort IP
Need to create a temporary file to hold some results? man mktemp (and remove it later remember the trap command in scripts?)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
