【SHELL】统计Nginx访问日志状态码
2016-05-30 11:29
766 查看
######################################################################### # File Name: check_nginx_server.sh # Author: Moshiyou # mail: momo1a@qq.com #Created Time:Mon 30 May 2016 10:21:52 AM CST ######################################################################### #!/bin/bash settrem=$(tput sgr0) Check_Nginx_Server_Log() { httpCode=(`cat /usr/local/nginx/logs/access.log | grep -ioE "HTTP/1\.[1|2]\"[[:blank:]][0-9]{3}" | awk -F "[ ]+" '{ $2!=""?code[$2]++:"" if($2>=100&&$2<200) {i++} else if($2>=200&&$2<300) {j++} else if($2>=300&&$2<400) {k++} else if($2>=400&&$2<500) {n++} else if($2>=500) {p++} }END{print i?i:0,j?j:0,k?k:0,n?n:0,p?p:0,i+j+k+n+p,code[404],code[403],code[500]}'`) echo -e '\E[32m'"The status number [100+] num:" $settrem ${httpCode[0]} echo -e '\E[32m'"The status number [200+] num:" $settrem ${httpCode[1]} echo -e '\E[32m'"The status number [300+] num:" $settrem ${httpCode[2]} echo -e '\E[32m'"The status number [400+] num:" $settrem ${httpCode[3]} echo -e '\E[32m'"The status number [500+] num:" $settrem ${httpCode[4]} echo -e '\E[32m'"The status all num:" $settrem ${httpCode[5]} echo -e '\E[32m'"The status 404 num:" $settrem ${httpCode[6]} echo -e '\E[32m'"The status 403 num:" $settrem ${httpCode[7]} echo -e '\E[32m'"The status 500 num:" $settrem ${httpCode[8]} } Check_Nginx_Server_Log
相关文章推荐
- android wifi 无线调试
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Nginx+Naxsi部署专业级Web应用防火墙
- Seafile Server本地权限提升漏洞(CVE-2014-5443)
- 从USB安装Ubuntu Server 10.04.3 图文详解
- CentOS 6.2实战部署Nginx+MySQL+PHP
- 文本处理工具AWK详解
- Linux Shell常用技巧
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Shell 脚本编程陷阱
- 使用zabbix监控Nginx活动状态--Part1
- 高效访问Internet-启用ISA Server的缓存