zoukankan      html  css  js  c++  java
  • awk 使用案例

    1.输出占用率超过60%的分区

     df -h | awk 'BEGIN{print "Full Partition"}NR>1{gsub("%","",$5);$5+=0;if($5>=60){print $1"	"$5}}'

     2. 停止占用8080端口的進程

    lsof -i:8080 | awk 'NR!=1{print $2}' | xargs kill -sigkill

     3.传入变量

    # 不使用 -v参数
    echo | awk  'END{print user}' user="$USER"

    # 使用 -v 参数 echo | awk -v user="$USER" '{print user}' echo | awk -v user="$USER" 'END{print user}' awk -v user="$USER" 'BEGIN{print user}'

     4.查询慢请求

    文本格式

    [12/Oct/2018:00:00:36 +0800] 10.0.2.40 GET /actuator/health HTTP/1.0  200 ( 0 ms )
    [12/Oct/2018:00:00:39 +0800] 10.0.1.40 GET /actuator/health HTTP/1.0  200 ( 1 ms )
    [12/Oct/2018:00:00:40 +0800] 10.0.2.40 GET /actuator/health HTTP/1.0  200 ( 1 ms )
    [12/Oct/2018:00:00:43 +0800] 10.0.1.40 GET /actuator/health HTTP/1.0  200 ( 2 ms )
    [12/Oct/2018:00:00:43 +0800] 10.0.2.40 GET /actuator/health HTTP/1.0  200 ( 1 ms )
    [12/Oct/2018:00:00:45 +0800] 127.0.0.1 HEAD /actuator/health HTTP/1.1  200 ( 2 ms )
    [12/Oct/2018:00:00:46 +0800] 10.0.1.40 GET /actuator/health HTTP/1.0  200 ( 2 ms )

    查询命令: URL是/config/edit 且 处理时长大于100毫秒

    awk '{ if ( $(NF-2) > 100 && $5=="/config/edit" ) print $0}' /opt/ali/config-web/backup/access_log.2018-10-*.log
    

      

  • 相关阅读:
    ELK 一些截图
    AD域
    NPOI
    搭建harbor
    【【【【日常问题记录】】】】
    golang yaml配置文件解析
    golang操作mysql使用总结
    【转】mysql优化步骤
    【转】Mysql事务,并发问题,锁机制
    golang curl
  • 原文地址:https://www.cnblogs.com/zhengwenqiang/p/7403773.html
Copyright © 2011-2022 走看看