原文出自:http://sarg.sourceforge.net/sarg.php
here are three scripts for daily, weekly and monthly statistics. After the monthly statistics the access.log will be rotated. This is based on Jeremy Lahners first script on your web page, many thanks to him. Daily (Jeremy´s script): ------------------------------------- #!/bin/bash #Get current date TODAY=$(date +%d/%m/%Y) #Get one week ago today YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y) /usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/daily -z -d $YESTERDAY-$TODAY
编者注:不知道原作者使用的是什么版本的sarg,在我测试时是没有sqmgrlog这个命令的,我是使用以下文件做的: /usr/bin/sarg -l /var/log/squid/access.log -o /var/www/html/sarg/monthly -z -d $YESTERDAY-$TODAY > /dev/null 2>&1 exit 0
Weekly ------------------------------------- #!/bin/bash #Get current date TODAY=$(date +%d/%m/%Y) #Get one week ago today YESTERDAY=$(date --date "1 week ago" +%d/%m/%Y) /usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/weekly -z -d $YESTERDAY-$TODAY exit 0
Monthly #!/bin/bash #Get current date TODAY=$(date +%d/%m/%Y) #Get one week ago today YESTERDAY=$(date --date "1 month ago" +%d/%m/%Y) /usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/monthly -z -d $YESTERDAY-$TODAY /usr/local/squid/bin/squid -k rotate exit 0
And the same for the admin who want the report as an email (example for daily) #!/bin/bash #Get current date TODAY=$(date +%d/%m/%Y) #Get one week ago today YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y) /usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -e user@site.com -z -d $YESTERDAY-$TODAY
exit 0 ~
Cheers Lars
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15453509/viewspace-448681/ ,如需转载,请注明出处,否则将追究法律责任。