https://my.oschina.net/hmc0316/blog/112004

实例:
月份英文简写英文全称
一月Jan.January
二月Feb.February
三月Mar.March
四月Apr.April
五月May.May
六月June.June
七月July.July
八月Aug.Aguest
九月Sept.September
十月Oct.October
十一月Nov.November
十二月Dec.December

日志分析整理 Grep 日志整理

1、分析日志文件下 2012-05-04 访问页面最高 的前20个 URL  并排序
cat access.log |grep '04/May/2012'| awk '{print $11}'|sort|uniq -c|sort -nr|head -20

2、查询受访问页面的URL地址中 含有 www.abc.com 网址的 IP 地址
cat access_log | awk '($11~/\www.abc.com/){print $1}'|sort|uniq -c|sort -nr

3、获取访问最高的10个IP地址  同时也可以按时间来查询
cat linewow-access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10

4、获得访问前10位的ip地址
cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'

5、访问次数最多的文件或页面,取前20及统计所有访问IP
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20
awk '{ print $1}' access.log |sort -n -r |uniq -c|wc -l
cat wangsu.log | egrep '06/Sep/2012:14:35|06/Sep/2012:15:05' |awk '{print $1}'|sort|uniq -c|sort -nr|head -10   查询日志中 时间段内的情况

6、列出传输最大的几个exe文件(分析下载站的时候常用)
cat access.log |awk '($7~/\.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -20

7、列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数
cat access.log |awk '($10 > 200000 && $7~/\.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -100

8、如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面
cat access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

9、列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cat access.log |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

10、列出传输时间超过 30 秒的文件
cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20

11、统计网站流量(G)
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'

12、统计404的连接
awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort

13、统计http status.
cat access.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn

14、每秒并发:
awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}'|sort -k 2 -nr|head -n10

15、带宽统计
cat apache.log |awk '{if($7~/GET/) count++}END{print "client_request="count}'
cat apache.log |awk '{BYTE+=$11}END{print "client_kbyte_out="BYTE/1024"KB"}'

16、找出某天访问次数最多的10个IP
cat /tmp/access.log | grep "20/Mar/2011" |awk '{print $3}'|sort |uniq -c|sort -nr|head

17、当天ip连接数最高的ip都在干些什么:
cat access.log | grep "10.0.21.17" | awk '{print $8}' | sort | uniq -c | sort -nr | head -n 10

18、找出访问次数最多的几个分钟
awk '{print $1}' access.log | grep "20/Mar/2011" |cut -c 14-18|sort|uniq -c|sort -nr|head

附:

1.查看tcp连接状态
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
netstat -ant|awk '/ip:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -n
netstat -ant|awk '/:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -rn|head -n 10
awk 'BEGIN{printf ("http_code\tcount_num\n")}{COUNT[$10]++}END{for (a in COUNT) printf a"\t\t"COUNT[a]"\n"}'

2.查找请求数前20个IP(常用于查找攻来源):
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n20

3.用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

4.查找较多time_wait连接
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

5.找查较多的SYN连接
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

6.根据端口列进程
netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1

linux下grep分析apache日志的命令集合的更多相关文章

  1. ubutun 下webalizer 分析Apache日志

    http://www.webalizer.org/  配置Webalizer 我们可以通过命令行配置Webalizer,也可以通过配置文件进行配置.下面将重点介绍使用配置文件进行配置,该方法使用形式比 ...

  2. (笔记)Linux下的解压、压缩命令集合

    01-.tar格式解包:[*******]$ tar xvf FileName.tar打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压缩! ...

  3. linux下查看动态链接库依赖关系的命令 x86: ldd *.so arm: arm-linux-readelf -d *.so 实际例子: 以项目中用到的库librtsp.so分析: lijun@ubuntu:~/workspace$ arm-hisiv100nptl-linux-ld -d librtsp.so arm-hisiv100nptl-linux-ld:

    linux下查看动态链接库依赖关系的命令 x86:ldd    *.so arm:arm-linux-readelf    -d    *.so 实际例子:以项目中用到的库librtsp.so分析:l ...

  4. 构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock

    构建LINUX下的入侵检测系统——LIDS   系统管理命令--vlock http://blog.chinaunix.net/uid-306663-id-2440200.html LIDS官方网站: ...

  5. Linux下编译安装Apache Http Server

    Linux下编译安装Apache Http Server [TOC] 1.下载httpd-2.4.12.tar.bz2 wget http://mirror.bit.edu.cn/apache/htt ...

  6. 如何分析apache日志[access_log(访问日志)和error_log(错误日志)]

    如何分析apache日志[access_log(访问日志)和error_log(错误日志)] 发布时间: 2013-12-17 浏览次数:205 分类: 服务器 默认Apache运行会access_l ...

  7. Linux下一个简单的日志系统的设计及其C代码实现

    1.概述 在大型软件系统中,为了监测软件运行状况及排查软件故障,一般都会要求软件程序在运行的过程中产生日志文件.在日志文件中存放程序流程中的一些重要信息, 包括:变量名称及其值.消息结构定义.函数返回 ...

  8. 在linux下手动安装 apache, php, mysql--终极版

    在linux下手动安装 apache, php, mysql: 参考: http://www.cnblogs.com/lufangtao/archive/2012/12/30/2839679.html ...

  9. elk系列7之通过grok分析apache日志【转】

    preface 说道分析日志,我们知道的采集方式有2种: 通过grok在logstash的filter里面过滤匹配. logstash --> redis --> python(py脚本过 ...

随机推荐

  1. JZOJ5988 珂学计树题

    题意 liu_runda曾经是个喜欢切数数题的OIer,往往看到数数题他就开始刚数数题.于是liu_runda出了一个数树题.听说OI圈子珂学盛行,他就在题目名字里加了珂学二字.一开始liu_rund ...

  2. 论文阅读笔记(六)【TCSVT2018】:Semi-Supervised Cross-View Projection-Based Dictionary Learning for Video-Based Person Re-Identification

    Introduction (1)Motivation: ① 现实场景中,给所有视频进行标记是一项繁琐和高成本的工作,而且随着监控相机的记录,视频信息会快速增多,因此需要采用半监督学习的方式,只对一部分 ...

  3. 48.Python中ORM模型实现mysql数据库基本的增删改查操作

    首先需要配置settings.py文件中的DATABASES与数据库的连接信息, DATABASES = { 'default': { 'ENGINE': 'django.db.backends.my ...

  4. js 弹窗插件

    toastr 参考 https://www.cnblogs.com/fu-yong/p/8609597.html prettyPhoto使用 参考

  5. CTF中压缩文件的常见解法

    此篇记录两篇记录的比较好的关于压缩文件破解的总结 链接:https://blog.csdn.net/xuqi7/article/details/71437882 https://blog.csdn.n ...

  6. 使用Vmware过程中,突然网络连接不上问题

    ###第一次的解决方法: 1.我一般过一段时间就会对虚拟机进行拍快照备份:在使用过程中,如果没有太大变化,恢复网络正常的快照一般是能解决问题的,但是要记得恢复快照之前要备份你已经修改过的所有东西,以防 ...

  7. C++中的参数类型

    C++中的参数类型 数组 数组是相同类型数据的集合.引入数组就不需要在程序中定义大量的变量,大大减少程序中变量的数量,使程序精炼,而且数组含义清楚,使用方便,明确地反映了数据间的联系.许多好的算法都与 ...

  8. AcWing 1018. 最低通行费

    #include<iostream> using namespace std ; ,INF=1e9; int dp[N][N],w[N][N]; int n; int main() { c ...

  9. 算法竞赛入门经典第二版 蛇形填数 P40

    #include<bits/stdc++.h> using namespace std; #define maxn 20 int a[maxn][maxn]; int main(){ ; ...

  10. git的分支

    git branch : git branch  -r  #查看远程分支 git branch -a  #查看本地分支和远程分支 git branch  -v  #查看本地库的所有分支 git  br ...