Querying unix web logs:

Frequently a webmaster will get requests concerning the nature of traffic at a web site. Here are some simple ways of generating reports.

command/output explanation
 

 

$ tail -2 $log
205.149.79.65 - - [04/Nov/1999:09:04:51 -0500] "GET /~dat1071/blinkpic.jpg HTTP/
1.1" 200 86309
192.148.234.75 - - [04/Nov/1999:09:46:11 -0500] "HEAD / HTTP/1.0" 200 0
$ tail -2 $log.1
205.149.65.61 - - [30/Oct/1999:21:44:09 -0400] "GET /~sxt1331/graphic1.jpg HTTP/
1.1" 200 1945
205.149.65.61 - - [30/Oct/1999:21:44:09 -0400] "GET /~sxt1331/graphic2.jpg HTTP/
1.1" 200 2751
$ tail -2 $log.2
205.149.69.143 - - [23/Oct/1999:23:39:48 -0400] "GET /~ddailey/passw.gif HTTP/1.
0" 200 3039
205.149.69.143 - - [23/Oct/1999:23:39:48 -0400] "GET /~ddailey/path.gif HTTP/1.0
" 200 11072
$ tail -2 $log.3
209.114.165.24 - - [17/Oct/1999:03:54:00 -0400] "GET /~ddailey/WebWizard.html HT
TP/1.0" 304 -
209.114.165.24 - - [17/Oct/1999:03:54:24 -0400] "GET /~ddailey/path.gif HTTP/1.0
" 304 -
Web access logs are typically kept in format as shown on the left: a series of records stored in archive files. The currently active file rolls over automatically, becoming renumbered. Higher numbered files refer to older data. Records consist of the IP address of the browser making the request, a time-stamp, and the material requested.
$ cut -d. -f1 $log|sort|uniq -c
      7 152
      7 171
    290 205
     12 208
     25 209                
Looking at IP addresses of incoming requests.
$ cat webstrings
205
dailey
gif
jpg               
Make a list of the strings of interest for tabulation.
for i in `cat webstrings`
do
echo ----------
echo *******$i
for j in 1 2 3 4
do
echo -----------
grep -c $i $log
echo '  'log.$j
done
done   
This little script (tucked away in a file called wcount) takes each line in the file webstrings and does a frequency count for the number of times that string occurs in the weblog file, for each of the archived web logs 1 through 4.
[ddailey@marble ddailey]$ ./wcount |more
----------
*******205
154
        log.1
-----------
1743 
        log.2
-----------
3776
        log.3
-----------
2366
        log.4

----------
*******dailey
-----------
75
         log.1
-----------
307
         log.2
-----------
1676
         log.3
-----------
189
         log.4

----------
*******gif
-----------
1883
         log.1
-----------
206
         log.2
-----------
479
         log.3
-----------
548
         log.4

----------
*******jpg
-----------
795
         log.1
-----------
1121
         log.2
-----------
2053
         log.3
-----------
1724
         log.4
The results of running the script are shown here.