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

前端之家收集整理的这篇文章主要介绍了利用开源工具处理nginx日志并定期生成html报告查看前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章