为了节省日志服务器的cpu,在awstats配置文件里我是这样写的
LogFile="/path_to_log/%YYYY%MM%DD-24"
意思就是只分析前一天的日志.但是没有想到awstats.pl这哥很不给力,每遇到跨月的时候总会扔给我一个错误:
- /path_to_awstats/awstats.pl -update -config=vod -lang=cn
- Create/Update database for config "/etc/awstats/vod.conf" by AWStats version 6.95 (build 1.943)
- From data in log file "/path_to_log/20110328"...
- Error: Couldn't open server log file "/path_to_log/20110328" : No such file or directory
- Setup ('/etc/awstats/vod.conf' file, web server or permissions) may be wrong.
- Check config file, permissions and AWStats documentation (in 'docs' directory).
提示:No such file or directory,仔细一看,明明才3.1号,结果给的是3.28号.看来是perl拼日期的时候拼错了.网上搜索一番发现竟然没有人提到这样的问题,难道大家分析日志的时候都是直接分析"path_to_log/*"?不管了,想想解决办法.分析awstats的源代码?我是没那爱好,先看下awstats.pl的参数吧.我很惊喜的发现了-LogFile参数.
-LogFile=x to change log to analyze whatever is 'LogFile' in config file
Be care to process log files in chronological order when updating statistics.
于是试了一下:
- /path_to_awstats/awstats.pl -update -config=vod -lang=cn -LogFile=/path_to_log/20110228
- Create/Update database for config "/etc/awstats/vod.conf" by AWStats version 6.95 (build 1.943)
- From data in log file "/path_to_log/20110228"…
- Phase 1 : First bypass old records, searching new record...
- Direct access to last remembered record has fallen on another record.
- So searching new records from beginning of log file...
- Jumped lines in file: 0
- Parsed lines in file: 2507347
- Found 0 dropped records,
- Found 1 corrupted records,
- Found 2507346 old records,
- Found 0 new qualified records.
不错,还真好使,那怎么得到正确的日期呢?
先试下php:
- php -r 'var_dump(date("Ymd",time()-86400));'
- string(8) "20110228"
再试一下shell:
- date +%Y%m%d -d yesterday
- 20110228
余下的事儿就简单了,拼个字符串,然后执行一下就好了,我选择的是php:
- <?php
- system('/path_to_awstats/awstats.pl -update -config=vod -lang=cn -LogFile='.date('Ymd',time()-86400));
- ?>
转载于:https://blog.51cto.com/rainbird/503417