zoukankan      html  css  js  c++  java
  • shell统计日志

    #nginx日志统计独立ip的个数:
    awk '{print $1}' /path-to-log-dir/access.log | sort | uniq | wc -l
    #查询访问最多的前10个ip
    awk '{print $1}' /path-to-log-dir/access.log  | sort | uniq -c | sort -nr | head -10
    #查看某段时间的
    grep "2012:0[3-6]" nginx.log |
    Active Internet connections (w/o servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40193 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40192 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40196 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40199 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40201 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40204 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40207 TIME_WAIT
    tcp 0 0 127.0.0.1:8652 127.0.0.1:40210 TIME_WAIT
    tcp 0 0 192.168.32.62:41682 192.168.47.207:5432 TIME_WAIT
    tcp 0 0 192.168.32.62:41685 192.168.47.207:5432 TIME_WAIT
    
    #访问次数最多的IP
    netstat -ntu | tail -n +3 | awk '{ print $5}' | cut -d : -f 1 | sort | uniq -c| sort -n -r | head -n 5
        tail -n +3 :去掉前两行。
        awk '{ print $5}':取数据的低5域(第5列)
        cut -d : -f 1 :取IP部分。
        sort:对IP部分进行排序。
        uniq -c:打印每一重复行出现的次数。(并去掉重复行)
        sort -n -r:按照重复行出现的次序倒序排列。
        head -n 5:取排在前5位的IP 
  • 相关阅读:
    Oracle简介
    Python 新建程序
    HTML 标记 3 —— CSS
    Dreamweaver 2
    Dreamweaver 1 网页制作
    has-a关系——多重私有继承
    has-a关系——包含对象成员的类
    《使用wxWidgets进行跨平台程序开发》chap02——一个简单的应用程序
    抽象基类(ABC),纯虚函数
    普通类继承
  • 原文地址:https://www.cnblogs.com/siqi/p/3610420.html
Copyright © 2011-2022 走看看