Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a program that parses Apache Common Log Format log files and produces a report. Your program will take the pathname of the log file to use as a command line argument. The report will always output the following items:
- Filename of the log file.
- Total number of bytes transferred
- The other report items will only be output if the appropriate command line arguments are specified:
- -h: Print a help message and exit without a report. The message should look something like the following output. You can add a longer description of the program's functionality.
- ApacheReport: An Apache Log Parser
- -h: Print a help message and exit without a report.
- -i: ASCII histogram of IP addresses.
- -u: ASCII histogram of URLs.
- -s: Sorted list of HTTP status codes, with percentages.
- apachereport [-h] [-i] [-u] [-s] logpath
- -i: ASCII histogram of IP addresses
- Output consists of two columns, the left containing IP addresses, and the right containing a histogram showing the number of accesses from that IP address. The histogram is constructed as a string of hash marks.
- 139.18.2.214 #
- 193.47.80.51 ##
- 203.199.84.66 ###
- 203.206.107.4 ##
- 62.101.126.216 ###########################
- 64.34.145.197 ##
- 65.214.44.29 #
- -u: ASCII histogram of URLs
- This option is similar to the previous option, which the difference that URLs have widely varying lengths, requiring you to truncate some of them to make the histogram readable. Add a vertical bar character at the end of a truncated URL so the reader knows what happened.
- /favicon.ico ##
- /manual/mod/mod_autoindex.html #
- /perl/faq/Windows/ ##
- /perl/faq/Windows/ActivePerl-Winf| #
- /perl/faq/Windows/ActivePerl-Winf| #
- /perl/perlmain.html #
- /robots.txt ########
- -s: Sorted list of HTTP status codes, with percentages of URLs that resulted in each status code, which should be printed like this example:
- HTTP Status Codes Summary:
- 200: 90%
- 301: 8%
- 401: 1%
- 404: 1%
- Bytes transferred: 4338917
- Options can be specified in any order. An invocation of your program could look like any of the following examples:
- $ ./apachereport cit383/test_log
- $ ./apachereport -u test_log
- $ ./apachereport -u -i /var/log/test_log
- $ ./apachereport -s -u ~/test_log
- $ ./apachereport -i -s -u ../log/test_log
- If incorrect command line options are specified, .e.g. a non-existent option like -f or no filename being specified, then the program must print a help message that explains how to run the program and exit.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement