Question: Linux Shell Scripts and command lines Your assignment is to write a shell script named astats.sh. You may also need to write a few additional

Linux Shell Scripts and command lines Your assignment is to write a shell script named astats.sh. You may also need to write a few additional small chunks of code in Awk or Perl or something as well. 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/wmahoney/IASC3350/files/access_log Request: -h Print this long message IPs print a sorted list of all unique IP addresses that have accessed the server within the past timeframe, and a total count at the end Users print all unique user names whose web pages have been accessed within the past timeframe, and a total count at the end Timeframe: day Use the log contents within the prior 24 hours week Use the log contents within the prior seven-day period month Use the log contents within the past month -N Go back exactly N days (e.g. -7 is the same as week) So for example: ./astats.sh IPs week will examine /home/wmahoney/IASC3350/files/access_log and provide a sorted list of all unique IP accesses within the past seven days, 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 on one line): 174.71.76.52 - - [01/Dec/2016:17:22:34 -0600] "GET /~csymons/project/css/normalize.css HTTP/1.1" 304 - 2 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 Want to know what day it was a week ago? man date (and look at d and +format) Need to create a temporary file to hold some results? man mktemp (and remove it later remember the trap command in scripts?) Want to know how to print the right parts of the file? Maybe you could just go steal the file /home/wmahoney/IASC3350/sel.awk and use it with my permission. If you have a shell variable with the correctly formatted date and pass it to this awk script, well. Need I say more? Apparently so! You can modify this awk program to get the user, for example. Ill leave that up to you to play with. Note: If today is for example December 8, and I run the script and specify week, what really should happen is that you handle all the records from December 1 through the end of the file. So terms like week really just set the starting point for data collection, and you work from that starting point to the end. (In the real world the log would be current right up to the instant you run the script, containing only data up to that instant, but we are using canned data for our assignment.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!