#!/bin/sh # many-sites-shared-log, Copyright 2000 Boutell.Com, Inc. # # EXAMPLE SCRIPT FOR ANALYZING MANY WEB SERVERS ON # A NIGHTLY BASIS, WITH ONE SHARED LOG FILE. LOG # ROTATION AND LOG ARCHIVING ARE PROVIDED. # # YOU *ABSOLUTELY WILL NEED TO MODIFY THIS SCRIPT.* Please # read it carefully, especially Step Three below. # # THIS SCRIPT REQUIRES ENOUGH DISK SPACE FOR A SECOND COPY # OF THE CURRENT LOG FILE. YOU CAN AVOID THIS BY MODIFYING # THE SCRIPT, BUT WE DO NOT RECOMMEND THIS. Be aware that # accesses that occur during the time the script is running, # or while log data is being archived, might not be # analyzed if you make such modifications. # # This Unix shell script analyzes many web sites with # one shared log file, and then proceeds to compress # and archive the log data. The script should be # invoked as follows, with no arguments: # # many-sites-shared-log # # The script assumes that the single-site-shared-log # script is present and correctly configured in the # directory changed to in step one, below. Please read # and, if necessary, edit that script before using this one. # # This script assumes that your log file is called # /var/log/httpd/access-log, and that archived log files # should be placed in the directory # /var/log/httpd/archived-logs. # # All of this must be true for the script to actually work! # If any of this is not true, you must adjust the script to # meet your needs. # # It is typical to invoke this script late at night, using # a crontab entry. # STEP ONE # Log rotation and archiving # Copy the current log data, and then immediately clear the log file. # This ensures that all accesses are analyzed, either tonight or on the # following night. This also requires a lot of disk space. Alternate # solutions have performance penalties and/or a risk of lost data. # We recommend that you stick with this approach. # A. Copy the log data cp /var/log/httpd/access-log /var/log/httpd/access-log-current # B. Clear the log file without recreating it. This ensures # that the web server will continue to log to it. cat /dev/null > /var/log/httpd/access-log # C. Create the archive directory if it does not already exist mkdir -p /var/log/httpd/archived-logs # D. Switch to that directory cd /var/log/httpd/archived-logs # E. Archive the log data we have just captured by compressing it # and storing it in an alternate directory. cat /var/log/httpd/access-log-current | gzip > log-`date +%Y.%m%d.%H%M%S`.gz # STEP TWO # Change to the directory where wusage and its configuration # files are located. cd /home/sites/home/users/admin/wusage # STEP THREE # Run single-site-shared-log one or more times for # individual sites. REPLACE THE CLIENT NAMES BELOW # with the names of YOUR web servers. Add or remove # lines as needed! ./single-site-shared-log client1 ./single-site-shared-log client2 ./single-site-shared-log client3 ./single-site-shared-log client4 #STEP FOUR # Remove the temporary copy of the log data used for # analysis and archiving purposes. rm /var/log/httpd/access-log-current # That's it!