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

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

#!/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 >> $webreport_path/index.html
	done
	echo "</html>" >> $webreport_path/index.html
}

webreport_create &&
reporthtml_create