Home Page > Useful GNU/Linux Scripts > Combining and Sorting Chronologically Apache Log Files
Although every care has been taken to provide accurate information, I do not warrant the accuracy or completeness of the information included in this website. Any use, or reliance on, such information is entirely at user's own risk.

Useful GNU/Linux Scripts: Combining and Sorting Chronologically Apache Log Files

Thanks to: Royans K Tharakan (rkt@pobox.com)

There are 2 reasons why I need these scripts...

  • I have 2 webservers behind my firewall and the primary Apache webserver (which receives all requests for port 80) proxies for the IIS webserver that only has an internal IP address (*See Below). I therefore am able to log requests for the IIS server using the Apache logs.
  • I like having separate logs for every domain that I host. This lets me run analysis for just one domain (using AWStats, Webalizer, Relax, etc.). This script will allow me to combine all traffic and analyze the logs combined.

Script: /usr/local/bin/combinelogs.sh

Additional Information:
This script merges all the logs into one file but doesn't sort the content.

S
C
R
I
P
T

 

Script: /root/mergelogs.pl

Additional Information:
Many of the log analysis programs that I use (AWStats, Webalizer, etc.) require that the log entries be in chronological order. This is required in order to track individual visitor sessions. This script sorts the logs entries chronologically.

S
C
R
I
P
T

 

Config File: /etc/apache/httpd.conf

Additional Information:

Here is a snip from the Apache config file to show you how I use Apache to proxy requests to the internal IIS webserver. This is necessary because I only have one static IP address on the Internet and therefore only have one port 80 that I can redirect to one webserver.

Since I have a website (cubalibre.org) that I wrote long ago using ASP, I have to keep an IIS server on my network. I know, I can buy ChiliSoft ASP, but I don't have thousands of dollars to spend. I'm glad I'm now using PHP for all present and future websites I design, but I don't feel like redoing my ASP code.

By having the Apache webserver as the frontline webserver, this has the additional benefit that the IIS server is not exposed to the Internet and is protected from CodeRed and any future malicious attacks that target IIS.

C
O
N
F
I
G

"Choose a job you love, and you will never have to work a day in your life." - Unknown Sage
.