将cronolog生成的apache日志合并到一个日志
以前服务器的awstats都是按照各个站点的顶级域名和二级域名进行统计的
没有一个站点总体的访问量
刚开始的解决方法是让每个域名写两个access的日志
一个写在自己域名的log中,另外一个写在总的log中
然后总的统计就是读取那个共用的log
昨天感觉这样不太好
于是打算用sort来合并日志
我的apache日志记录的格式是:
CustomLog “|/usr/local/sbin/cronolog /var/log/httpd/taoer.com/blog/%Y/%m/taoer_blog_access_log.%Y%m%d” combined
awstats的LogFile是:
LogFile = “/var/log/httpd/taoer.com/blog/%YYYY/%MM/taoer_blog_access_log.%YYYY%MM%DD”
用sort合并的脚本是:
#!/bin/sh
Domain=$1
Site=$2
Year=`date -u +%Y`
Month=`date -u +%m`
Day=`date -u +%d`
dPath=
“/var/log/httpd/$Domain/$Site/$Year/$Month/taoer_all_access_log.$Year$Month$Day”
sPath=
“/var/log/httpd/$Domain/*/$Year/$Month/*.$Year$Month$Day”
if [ ! -x "$logPath/$Domain/" ]; then
mkdir “$logPath/$Domain/”
echo “Now, Make Dir $logPath/$Domain/ …”
fi
if [ ! -x "$logPath/$Domain/$Site/" ]; then
mkdir “$logPath/$Domain/$Site/”
echo “Now, Make Dir $logPath/$Domain/$Site/ …”
fi
if [ ! -x "$logPath/$Domain/$Site/$Year/" ]; then
mkdir “$logPath/$Domain/$Site/$Year/”
echo “Now, Make Dir $logPath/$Domain/$Site/$Year/ …”
fi
if [ ! -x "$logPath/$Domain/$Site/$Year/$Month/" ]; then
mkdir “$logPath/$Domain/$Site/$Year/$Month/”
echo “Now, Make Dir $logPath/$Domain/$Site/$Year/$Month/ …”
fi
if [ ! -f "$dPath" ]; then
touch $dPath
echo “Now, Touch File $dPath …”
fi
echo “Now: ReadFile From $sPath”
echo “Now: WriteFile To $dPath”
#sort -m -t ” ” -k 4 -o /var/log/httpd/$Domain/$Site/$Year/$Month/taoer_all_access_log.$Year$Month$Day /var/log/httpd/$Domai
n/*/$Year/$Month/*.$Year$Month$Day
touch $dPath
sort -m -t ” ” -k 4 -o $dPath $sPath
这样,每次合并下,感觉要比每次记录两次要好些
