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.198.33
      1 111.206.198.12
      1 109.125.166.71
      1 106.39.246.8
      1 106.15.200.123
      1 103.42.254.240
      1 101.200.201.208
      1 101.132.99.248
      1 101.132.78.143
      1 101.132.69.5