#!/bin/sh # single-site-private-log, Copyright 2000 Boutell.Com, Inc. # # EXAMPLE SCRIPT FOR ANALYZING A SINGLE SERVER ON # A NIGHTLY BASIS, WITH LOG ROTATION AND LOG ARCHIVING # # THIS SCRIPT REQUIRES ENOUGH DISK SPACE FOR A SECOND COPY # OF THE CURRENT LOG FILE. YOU CAN AVOID THIS BY MODIFYING # THE SCRIPT. However, 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. # # YOU MAY NEED TO MODIFY THIS SCRIPT. READ IT CAREFULLY. # # This Unix shell script analyzes a single web site with # its own private log file, and then proceeds to compress # and archive its log data. The name of the web site should # be specified on the command line, like so, without the # '#' symbol in front: # # single-site-private-log companyname # # The script will then assume that your configuration file is # called companyname.conf, your log file is called # companyname.log, your report directory is # /home/sites/home/users/companyname/web/usage, and # your log files are kept in a directory called # /var/log/httpd. Archived log files will be placed # in /home/sites/home/users/companyname/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 run this script late at night, using # a crontab entry. If you choose to run it as root, # you will wish to uncomment either the 'chmod' line or # the 'chown' line below, to make the reports world readable # or assign them to a specific Unix user. If you choose to run # it as an appropriate user it may not be necessary to do either. # 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/$1.log /var/log/httpd/$1.current.log # 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/$1.log # C. Create the archive directory if it does not already exist mkdir -p /home/sites/$1/archived-logs # D. Switch to that directory cd /home/sites/$1/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/$1.current.log | 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 the wusage program. Specify a specific configuration # file and log file. ./wusage -c $1.conf -l /var/log/httpd/$1.current.log # STEP FOUR # Change the ownership and/or permissions of the report files # so that they can be seen by a web server running as a specific # user, OR by everyone. Uncomment ONE of these options by removing # the # in front of the chmod or chown line. If you are running # this script as an appropriate user, not as root, then it # is often unnecessary to do either one. # # IF YOU WANT PRIVACY FOR YOUR REPORTS, use the features of your # web server to password-protect the directory in which they # are kept. This is quite straightforward. See your web server's # documentation. # OPTION A: make reports readable by all accounts #chmod -Rf 755 /home/sites/$1/web/usage # OPTION B: give the reports to one specific account. # The company name must be the SAME as the account name. # If this is not true, you will need to customize this script. #chown -Rf $1 /home/sites/$1/web/usage # STEP FIVE # Remove the temporary copy of the log data used for # analysis purposes. rm /var/log/httpd/$1.current.log # That's it!