Chinaunix首页 | 论坛 | 博客
  • 博客访问: 417304
  • 博文数量: 54
  • 博客积分: 1186
  • 博客等级: 少尉
  • 技术积分: 668
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 04:57
文章分类

全部博文(54)

文章存档

2013年(1)

2012年(6)

2011年(47)

我的朋友

分类: LINUX

2012-06-11 01:40:02

Linux最爽的地方就是可以通过组合各种小工具来实现强大的功能,现在总算有些体会了。

在Windows下要想分析网站日志文件怎么办?很遗憾,您只能自己写程序来实现了。而在Linux下,就很简单了。

比如我要查看某网站中百度蜘蛛的爬行记录,那么我可以使用以下命令:

cat access.log | grep "Baiduspider" | awk '{printf("%-25s%-60s%-20s%-5s\n",$4,$7,$9,$10)}'

其中“access.log”是网站的日志文件;“grep”是在日志文件中进行搜索;awk是格式化输出,使用方法与C中的printf相同。

贴一下该命令的输出格式:

[10/Jun/2012:08:10:18    /gps/1/feed                                                 200                 41941
[10/Jun/2012:08:10:21    /86.html/feed                                               200                 838
[10/Jun/2012:08:10:22    /gps/4/feed                                                 200                 39231
[10/Jun/2012:08:10:25    /8.html/feed                                                200                 810
[10/Jun/2012:08:10:25    /51.html/feed                                               200                 839
[10/Jun/2012:08:10:29    /103.html/feed                                              200                 849
[10/Jun/2012:08:10:29    /114.html/feed/atom                                         200                 721
[10/Jun/2012:08:10:33    /103.html/feed/atom                                         200                 762
[10/Jun/2012:08:10:33    /94.html/feed/atom                                          200                 709
[10/Jun/2012:08:10:37    /108.html/feed/atom                                         200                 761
[10/Jun/2012:08:10:37    /99.html/feed/atom                                          200                 736
[10/Jun/2012:08:10:41    /96.html/feed/atom                                          200                 721
[10/Jun/2012:08:10:41    /112.html/feed/atom                                         200                 759
[10/Jun/2012:08:10:45    /110.html/feed/atom                                         200                 738
[10/Jun/2012:08:10:45    /101.html/feed/atom                                         200                 753
[10/Jun/2012:08:10:49    /105.html/feed/atom                                         200                 706
[10/Jun/2012:08:10:50    /gps/10/feed                                                200                 39345
[10/Jun/2012:08:10:53    /gps/14/feed                                                200                 12972
[10/Jun/2012:08:10:53    /99.html/feed                                               200                 824
[10/Jun/2012:08:10:57    /40.html/feed                                               200                 803
[10/Jun/2012:08:10:57    /21.html/feed                                               200                 812
[10/Jun/2012:08:11:01    /author/jjxiaoyan/page/2                                    200                 6409
[10/Jun/2012:08:11:01    /author/jjxiaoyan/page/5                                    200                 5076
[10/Jun/2012:08:11:05    /author/jjxiaoyan/feed                                      200                 59261
[10/Jun/2012:08:11:06    /author/jjxiaoyan/page/3                                    200                 6316
[10/Jun/2012:08:11:07    /author/jjxiaoyan/page/4                                    200                 6487
[10/Jun/2012:08:11:11    /92.html/feed                                               200                 818
[10/Jun/2012:08:11:11    /65.html/feed                                               200                 818
[10/Jun/2012:08:11:15    /78.html/feed                                               200                 845
[10/Jun/2012:08:11:15    /23.html/feed                                               200                 806
[10/Jun/2012:08:11:19    /34.html/feed                                               200                 815
[10/Jun/2012:08:11:19    /76.html/feed                                               200                 806
[10/Jun/2012:08:11:23    /71.html/feed                                               200                 809
[10/Jun/2012:08:11:23    /67.html/feed                                               200                 812
[10/Jun/2012:08:11:27    /60.html/feed                                               200                 809
[10/Jun/2012:08:11:27    /57.html/feed                                               200                 812
[10/Jun/2012:08:11:31    /date/2012/06/                                              301                 5
[10/Jun/2012:08:11:31    /date/2012/06                                               200                 10541
[10/Jun/2012:08:11:32    /date/2012/05/                                              301                 5
[10/Jun/2012:08:11:33    /date/2012/05                                               200                 10874
[10/Jun/2012:10:19:57    /                                                           200                 12831


阅读(2232) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~