First, the Apache logs are cut by day
Vi/etc/httpd/conf/httpd.conf
Errorlog "|rotatelogs/var/log/httpd/%y%m%derror_log 86400 480"
Customlog "|rotatelogs/var/log/httpd/%y%m%daccess_log 86400 480" combined
Second, restart Apache service
Service httpd Restart
################# #apahce日志服务器按天切割完毕 ######################
Iii. analysis of the generated Apache log status code (waiting for a day's log)
Log file is 20111228access_log
 VI http.sh 
#!/ Bin/bash
total= ' cat 20111228access_log|wc-l '
array= (' Cat 20111228access_log |awk ' {print $9} ' |sort|uniq-c|sort-n ')
len=${#array [@]}
& nbsp echo "################### #http状态码统计 ###########################"
echo Total number of connections: $total
For ((i=0;i< $len; i=i+2))
{
echo "########################################################"
echo ${array[$i]}:${array[$i +1]}
echo "########################################################"
echo ${array[$i +1]} Percentage of connections: ' awk ' begin{printf '%.6f%\n ', (' ${array[$i]} '/' ${total} ' *100)} '
}
Execute script result (in percent sign):
SH http.sh
################### #http状态码统计 ###########################
Total number of connections: 688965
########################################################
1:303
########################################################
303 Percentage of connections: 0.000145%
########################################################
1:416
########################################################
416 Percentage of connections: 0.000145%
########################################################
2:299
########################################################
299 Percentage of connections: 0.00029%
########################################################
8:501
########################################################
501 Percentage of connections: 0.001161%
########################################################
145:403
########################################################
403 Percentage of connections: 0.021046%
########################################################
197:400
########################################################
400 percentage of connections: 0.028594%
########################################################
738:206
########################################################
206 Percentage of connections: 0.107117%
########################################################
7,307:404
########################################################
404 Percentage of connections: 1.060576%
########################################################
9,213:302
########################################################
302 Percentage of connections: 1.337223%
########################################################
30,574:301
########################################################
301 Percentage of connections: 4.437671%
########################################################
201,197:304
########################################################
304 Percentage of connections: 29.20279%
########################################################
439,582:200
########################################################
200 Percentage of connections: 63.803241%
####################### #简单讲解 #########################
Array= (' Cat 20111228access_log |awk ' {print $9} ' |sort|uniq-c|sort-n ')
# # #这个拿出来是一个数组了
len=${#array [@]}
# # #这个是数组的长度
echo ${array[$i]}:${array[$i +1]}
# # #这个是以for循环输入状态码和状态码的连接数
awk ' begin{printf '%.6f%\n, (' ${array[$i]} '/' ${total} ' *100)}
# # #以百分比计算各个状态码大约占的连接数
Shell script parsing Apache log status code