TOUVE 发表于 2018-8-26 10:30:21

linux下统计appche站点IP访问量的shell脚本

  这篇文章主要介绍了linux下统计appche站点IP访问量的几种shell脚本以及执行结果
  经常需要根据IP地址统计apache站点访问量,最基本的脚本.
  根据IP访问量降序排列:
  复制代码 代码如下:
  

#!/bin/bash  
#Script_name: access_count
  

  
acc_log=/usr/local/apache2/logs/access_log
  

  
/bin/awk '{print $1}' $acc_log| sort | uniq -c | sort -nr
  

  执行效果:
  复制代码 代码如下:
  

# sh access_count  94989 192.168.100.34
  38863 192.168.200.92
  23658 192.168.1.71
  16720 192.168.100.80
  13688 192.168.200.34
  1618 192.168.100.104
  1251 192.168.1.202
  1195 192.168.100.30
  1058 192.168.1.203
  934 192.168.1.208
  792 127.0.0.1
  773 192.168.5.126
  189 192.168.1.68
  

  打印访问量前三的IP地址:
  复制代码 代码如下:
  

#!/bin/bash  
#Script_name:access_count
  

  
acc_log=/usr/local/apache2/logs/access_log
  

  
/bin/awk '{print $1}' $acc_log| sort | uniq -c | sort -nr | head -n 3
  

  执行效果:
  复制代码 代码如下:
  

# sh access_count  94989 192.168.100.34
  38863 192.168.200.92
  23658 192.168.1.71
  

  apache站点访问错误统计:
  复制代码 代码如下:
  

#!/bin/bash  
#Script_name:error_count
  

  
err_log=/usr/local/apache2/logs/error_log
  

  
cat$err_log | grep -e "^\[" |awk '{print $6}' | sort | uniq -c |sort -nr
  

  执行效果:
  复制代码 代码如下:
  

# sh error_count  701
  30
  12
  1 [:error]


页: [1]
查看完整版本: linux下统计appche站点IP访问量的shell脚本