• linux实用的日志分析脚本


    日志分析

    随意的tail一个access_log文件,下面是一条经典的访问记录

    218.19.140.242 – - [10/Dec/2010:09:31:17 +0800] “GET /query/trendxml/district/todayreturn/month/2009-12-14/2010-12-09/haizhu_tianhe.xml HTTP/1.1″ 200 1933 “-” “Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)”

    实用的日志分析脚本
    了解日志的各种定义后,这里分享一下从网上淘来的一些对日志分析的脚本

    1.查看apache的进程数
    ps -aux | grep httpd | wc -l

    2.分析日志查看当天的ip连接数
    cat default-access_log | grep “10/Dec/2010″ | awk ‘{print $2}’ | sort | uniq -c | sort -nr

    3.查看指定的ip在当天究竟访问了什么url
    cat default-access_log | grep “10/Dec/2010″ | grep “218.19.140.242″ | awk ‘{print $7}’ | sort | uniq -c | sort -nr

    4.查看当天访问排行前10的url
    cat default-access_log | grep “10/Dec/2010″ | awk ‘{print $7}’ | sort | uniq -c | sort -nr | head -n 10

    5.看到指定的ip究竟干了什么
    cat default-access_log | grep 218.19.140.242 | awk ‘{print $1″ ”$8}’ | sort | uniq -c | sort -nr | less

    6.查看访问次数最多的几个分钟(找到热点)
    awk ‘{print $4}’ default-access_log |cut -c 14-18|sort|uniq -c|sort -nr|head

    7.统计一个文本中包含字符个数

    cat pic.access.log |grep /2012/ |wc -l

    cat c_access.log |grep "/message/publishmsg/|/message/publish/" >test1.log 

  • 相关阅读:
    Linux02--文件系统与磁盘管理
    Android02-Activity01
    Android01-概述
    LeetCode | Binary Tree Level Order Traversal II
    LeetCode | Binary Tree Level Order Traversal
    LeetCode | Binary Tree Postorder Traversal
    LeetCode | Binary Tree Inorder Traversal
    LeetCode | Binary Tree Preorder Traversal
    LeetCode | Symmetric Tree
    LeetCode | Balanced Binary Tree
  • 原文地址:https://www.cnblogs.com/liu-ke/p/4301827.html
Copyright © 2020-2023  润新知