help with /var folder

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

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

Im trying to make a script which will � Use the /var/www/logs/access_log file to process the last 300 lines (i.e.) the lines at the end of the file (user opentech to test this option).

  1. Relevant commands, code, scripts, algorithms:

so far Ive searched the directory for the /var/www/logs/access_log file but there is no /www directory or access_log directory
3. The attempts at a solution (include all code and scripts):

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    I currently attend Durham College Oshawa Canada Karl Alexander is my proffs name PROG3103. I dont have a link to the course website sorry :

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

find /var/ -name 'access_log'

Further to Corona688 who is showing you how to search the entire /var tree for a file called "access_log", this might need a deeper find if the file doesn't turn up easily.

First as user "root":

find /var/ -type f -xdev -follow -name access_log -print

There is a hint in the project that you must be user "opentech" to process this file, so "su" or "sudo" (if this is Linux) to the right user first before issuing your "tail -300" command. Actually changing user might well be enough to see the file "access_log". Try it out.

im supposed too Display a list of IP addresses and the number of times a connection is made from that IP address
that would be done by using grep and wc on a the last 300 lines in this certain file in /var/www/logs/access log?

whats the command to display a list of IP's and number time connection as been made

Start by looking at the log to see how you would identify a line which contains a connection from an IP address. This will be the rule for your first grep. If the whole log is just connections you don't need this stage.

Then look at sample connection lines and come up with some simple way of defining where the IP address is on that line (e.g. 5th space-delimited field). This will dictate your method to extract the IP address prior to sorting and counting. (If you have not studied "awk" this might just involve using "cut").

If there is no clear rule to fish out the IP address then you could be looking at a grep which finds patterns like nnn.nnn.nnn (or nnn.nnn.nnn.nnn if this is IP6) where nnn is a number 0-255 . Let's hope it is a simple format log.

We don't know what your log file looks like. Can you post a couple of sample lines.

There is a current thread on this board which may get you started on how to count occurances in a list.
http://www.unix.com/unix-dummies-questions-answers/172647-how-count-number-times-each-word-exist-file.html

access=""
tail access_log -n 300 > access
access | grep "ip address" -c | wc -l

this is what i got so far just trying to see how i can identify the ip address part from this access log.....

� Display a list of IP addresses and the number of times a connection is made from that IP address

I also command too do this as well. without using the access_log

Well, what do the contents of access_log look like?

1 Like