#!/bin/sh # Monthly web log archive shell script # Copyright 2002 Ben Livingston # Released under the GNU General Public License Version 2 # Viewable online at http://www.gnu.org/copyleft/gpl.html PATH="/bin:$PATH" # Get archived log name. date=`date -d "-1 month" +%y-%m` log_original=$date.log function CHECK_AND_MOVE () { # Prefix output echo -n "$domain: " # Run web log analysis /usr/local/sbin/weblog_analysis $domain # Get initial filename for each pass through log=$log_original; # If archive directory doesn't exist, create it. if [ ! -e /var/log/httpd/archive/$domain ]; then mkdir /var/log/httpd/archive/$domain; fi # Keep checking to see if filename. Add .blah as many times as needed while [ -e /var/log/httpd/archive/$domain/$log ]; do log=$log.blah; done # Move the log to the checked filename mv /var/log/httpd/$domain-access_log /var/log/httpd/archive/$domain/$log # HUP the httpd server kill -HUP `cat /usr/local/apache/logs/httpd.pid` # Fix permission and gzip the log, then sleep 2 seconds chmod 640 /var/log/httpd/archive/$domain/$log gzip /var/log/httpd/archive/$domain/$log sleep 2 } for domain in `cat /etc/vdomains`; do CHECK_AND_MOVE; done