awk 指定时间内的ip访问次数 可刷新运行 刷新

awk 指定时间内的ip访问次数

代码:

$start_time=date('d/M/Y:H:i:s',strtotime('-1 day'));
$stop_time=date('d/M/Y:H:i:s');
system("awk -F \" \" -v st=\"{$start_time}\" -v et=\"{$stop_time}\" '{t=substr($4,2);if(t>=st && t<=et){print $1}}' /var/log/nginx/*.log  |sort | uniq -c | sort -nr | tail -n 10 ");

//sheell 替换掉开始时间和结束时间
//awk -F " " -v st="09/Mar/2020:11:55:28" -v et="09/Mar/2020:12:27:24" '{t=substr($4,2);if(t>=st && t<=et){print $1}}' /var/log/nginx/access.log  |sort | uniq -c | sort -nr

输出:

      1 111.206.221.75
      1 111.206.221.68
      1 111.206.198.42
      1 111.206.198.12
      1 110.44.117.55
      1 106.14.140.68
      1 103.83.57.30
      1 103.245.34.178
      1 101.4.110.154
      1 101.132.109.130
遇到问题?