利用开源工具处理nginx日志并定期生成html报告查看

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
 
clear;
 
html_code='<!DOCTYPE HTML><html><head><meta charset="utf-8"><link rel="stylesheet" href="css/style.css" type="text/css" media="all"><title>后台数据报告</title></head><h1><strong>后台数据报告</strong></h1><h3><strong>---请点击</strong></h3>'
 
webreport_path="/path/nginx/html/webreport"
weblog_path="/path/nginx/logs"
 
 
 
function webreport_create()
{
    if [ "01" -eq $(date +"%d") ] ; then
        reportdate=$(date -d "last month" +"%Y%m");
        rm $webreport_path/web$reportdate*\.html
    else
        reportdate=$(date -d "yesterday" +"%Y%m%d");
    fi
    if [ -f $weblog_path/access.log-$reportdate\.gz ] ; then
        zcat -f $weblog_path/access.log-$reportdate\.gz |goaccess -a > $webreport_path/web$reportdate\.htm
    else
        cat $weblog_path/access.log-$reportdate |goaccess -a > $webreport_path/web$reportdate\.htm
    fi
    sed -i 's/IP/vm/g' $webreport_path/web$reportdate\.html &&
}
 
function reporthtml_create()
{
    echo $html_code > $webreport_path/index.html
    for i in $(cd $webreport_path ; echo web* )
    do
        inputhtml="<a href=\"$i\">${i%%.*}</a>"
        echo $inputhtml &gt;&gt; $webreport_path/index.html
    done
    echo "</html>" &gt;&gt; $webreport_path/index.html
}
 
webreport_create &&
reporthtml_create