#!/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