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
    

      

  • 相关阅读:
    短连接生成
    google 定位 标记 地址解码 逆解码
    Laravel 文件上传
    Laravel
    对接航信开票-在线二维码开票
    win 下 composer 安装
    对接美团外卖开放平台
    IOS 弹框在微信中导致输入框等失焦 偏移问题解决
    微信公众号-高德地图实例
    对接百度地图API 实现地址转经纬度
  • 原文地址:https://www.cnblogs.com/zhengwenqiang/p/7403773.html
Copyright © 2011-2022 走看看