Log file analyzer, super basic sh program

Hello! I'd like some help with this assignment.

  1. The problem statement, all variables and given/known data:

1)Write a shell script that can uses two types of files as inputs, apache.log and apache.error.log
2)Make it so that you can switch between the two file types
3)Make it so that the script writes the output in the terminal, and it is easily readable (use whitespace characters to separate the columns)

  1. Relevant commands, code, scripts, algorithms:
    awk commands

  2. The attempts at a solution (include all code and scripts):
    for task 2)

#!/bin/sh

echo "What type of file's contents would you like for me to print? 1 - apache.log, 2 - apache.error.log"
read NUM

case $NUM in
	1) # Print out apache.log's contents ;;
	2) # Print out apache.error.log's contents ;;
	*) echo "INVALID INPUT!" ;;
esac

I don't know how I could do task 3)

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    University of Miskolc, Miskolc, Hungary, Smid L�szl�, GE-BGI

Welcome to the forum.

Not bad a start. You now could use shell functions to fulfill the 3rd requirement. I'm not sure what that exactly is, but just copying the files to the terminal might be missing it. Wouldn't it be helpful to provide small but representative samples of either log file if you need further assistance?

Oh yeah, sorry.

for apache.log

x.x.x.90 - - [13/Sep/2006:07:01:53 -0700] "PROPFIND /svn/[xxxx]/Extranet/branches/SOW-101 HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:07:01:51 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/trunk HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:07:00:53 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/2.5 HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:07:00:53 -0700] "PROPFIND /svn/[xxxx]/Extranet/branches/SOW-101 HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:07:00:21 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/trunk HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:06:59:53 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/2.5 HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:06:59:50 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/trunk HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:06:58:52 -0700] "PROPFIND /svn/[xxxx]/[xxxx]/trunk HTTP/1.1" 401 587
x.x.x.90 - - [13/Sep/2006:06:58:52 -0700] "PROPFIND /svn/[xxxx]/Extranet/branches/SOW-101 HTTP/1.1" 401 587

for error

[Fri Dec 16 01:46:23 2005] [error] [client 1.2.3.4] Directory index forbidden by rule: /home/test/
[Fri Dec 16 01:54:34 2005] [error] [client 1.2.3.4] Directory index forbidden by rule: /apache/web-data/test2
[Fri Dec 16 02:25:55 2005] [error] [client 1.2.3.4] Client sent malformed Host header
[Mon Dec 19 23:02:01 2005] [error] [client 1.2.3.4] user test: authentication failure for "/~dcid/test1": Password Mismatch

Use a pager like more or less to display the files on screen.

I want the script to take an input like

./analyzer.sh 1 access_log

and print its contents.
Also to check if access_log is in the correct apache.log format, and if it isn't give back an error message.

I don't know how I could make that.

Do you want to read the log type from terminal, or do you want to pass it from the command line?
Do you know how to get at the script's positional parameters?
How would you describe the respective files' format, so it can be compared / controlled?