Using the shell to do the Nginx log analysis

Source: Internet
Author: User
Tags curl

#!/bin/bash

if [[$# = = 0]];then
echo "Error: Please enter the number of days to query???"
Else
echo "Temporarily does not support the 7 version of CentOS!!! "
now_time_cuo=date +%s
((end_time_cuo=${now_time_cuo}- echo $1*3600*24 | bc ))
Now_time=date | awk ‘{print $3"\\\/"$2"\\\/"$NF}‘
End_time=date -d @${END_TIME_CUO}| awk ‘{print $3"\\\/"$2"\\\/"$NF}‘

# #根据ip统计一段时间的UV
Echo-e "\033[31moutput Day ' s UV: \033[0m"
Cat access.log|grep-v curl|sed-n "/${end_time}/,/${now_time}/p" | awk ' {print '} ' | Sort| uniq-c| Wc-l

# #根据访问URL访问PV
Echo-e "\033[31moutput Day ' s PV: \033[0m"
Cat access.log|grep-v curl|sed-n "/${end_time}/,/${now_time}/p" | awk ' {print $7} ' | Wc-l

# #查询访问最频繁的URL
Echo-e "\033[31moutput Day's hot URL: \033[0m"
Cat access.log|grep-v curl|sed-n "/${end_time}/,/${now_time}/p" | awk ' {print $7} ' | Sort|uniq-c|sort-n-K 1-r|head

# #查询访问最频繁的IP
Echo-e "\033[31moutput Day ' s ten hot IP: \033[0m"
Cat Access.log| Grep-v curl|sed-n "/${end_time}/,/${now_time}/p" |awk ' {print '} ' |sort|uniq-c|sort-n-K 1-r|head

Fi
: <<down
1, according to the Access IP statistics UV
awk ' {print '} ' Access.log | Sort | uniq-c | Wc-l
2, Statistics access URL statistics PV
awk ' {print $7} ' Access.log | Wc-l
3. Query the most frequently accessed URLs
awk ' {print $7} ' Access.log | Sort | Uniq-c |sort-n-K 1-r | More
4. Query the most frequently accessed IP
awk ' {print '} ' Access.log | Sort | Uniq-c |sort-n-K 1-r | More
5, according to the time period Statistics view Log
Cat Access.log |sed-n '/14\/mar\/2015:21/,/14\/mar\/2015:22/p ' | More
Down

Using the shell to do the Nginx log analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.