日期:2014-05-17  浏览次数:20761 次

awk分析处理jenkins的log文件并生成HTML文件

?

?

?

#!/bin/bash
a=$1




##### ================pmd

log_xml="/var/www/html/yii/build/logs/pmd.xml"
export_html="/var/www/html/yii/build/logs/shell_email.html"

#多少报错文件
file_num=$(awk '{if($1~/<file/) print $2}' $log_xml | awk -F \" '{print $2}' |wc -l)

#多少message
#mess_num=$(awk -F \" '{if($1~/<violation/) print $2,$6,$8}' /var/www/html/yii/build/logs/pmd.xml |wc -l)
mess_num=$(awk '/<violation/{line++}END{print line}' $log_xml )

#详细列表
rs="<table border=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td height=\"22\" class=\"bg1\" colspan=\"4\"><p style=\"color:#FFFFFF\"><strong>PMD Result (files:$file_num  messages:$mess_num)</strong></p></td></tr><tr><td height=\"22\" bgcolor=\"#4040FF\">No</td><td height=\"22\" bgcolor=\"#4040FF\">Code num</td><td height=\"22\" bgcolor=\"#4040FF\">Message</td><td height=\"22\" bgcolor=\"#4040FF\">File</td></tr>"


#rs2=$(awk -F \" '/<file/{a=$2}/\<violation/{print "<tr><td>",i++,"</td><td>","<tr><td>",$2,"</td><td>",$8,"</td><td>",a,"</td></tr>"}' $log_xml |grep -v "<tr><td></td><td>")
rs2=$(awk -F \" '/<file/{a=$2}/<violation/{print "<tr><td>",++i,"</td><td>",$2,"</td><td>",$8,"</td><td>",a,"</td></tr>"}' $log_xml )

#IFS_old=$IFS
#IFS=$'\n'
#for loop in $aa
#do
#rs2="$rs2 <tr><td>$loop</td></tr>"
#done


echo "$rs $rs2</table><br><br>" > $export_html
#echo "$rs $rs2</table>" > /var/www/html/shell_email.html
#IFS=$IFS_old




##### ================checkstyle

log_xml="/var/www/html/yii/build/logs/checkstyle.xml"

#多少报错文件
file_num=$(awk '{if($1~/<file/) print $2}' $log_xml | awk -F \" '{print $2}' |wc -l)


#多少message
#mess_num=$(awk -F \" '{if($1~/<error/) print $6,$2,$8}' /var/www/html/yii/build/logs/checkstyle.xml |wc -l)
mess_num=$(awk '/<error/{line++}END{print line}' $log_xml)


#多少error
mess_num_error=$(awk '/severity=\"error\"/{line++}END{print line}' $log_xml)

#多少warnings
mess_num_warnings=$(awk '/severity=\"warning\"/{line++}END{print line}' $log_xml)

#详细列表
rs="<table border=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td height=\"22\" class=\"bg1\" colspan=\"5\"><p style=\"color:#FFFFFF\"><strong>Checkstyle Result (files:$file_num  messages:$mess_num error:$mess_num_error warnings:$mess_num_warnings)</strong></p></td></tr><tr><td height=\"22\" bgcolor=\"#4040FF\">No</td><td height=\"22\" bgcolor=\"#4040FF\">Type</td><td height=\"22\" bgcolor=\"#4040FF\">line</td><td height=\"22\" bgcolor=\"#4040FF\">Message</td><td height=\"22\" bgcolor=\"#4040FF\">File</td></tr>"


#rs2=$(awk -F \" '/<file/{a=$2} /<error/{print "<tr><td>",++i,"</td><td>",$6,"</td><td>",$2,"</td><td>",$8,"</td><td>",a,"</td></tr>"}' $log_xml | grep -v "<tr><td></td><td></td><td>")
rs2=$(awk -F \" '/<file/{a=$2}/<error/{print "<tr><td>",++i,"</td><td>",$6,"</td><td>",$2,"</td><td>",$8,"</td><td>",a,"</td></tr>"}' $log_xml )

#IFS_old=$IFS
#IFS=$'\n'
#for loop in $aa
#do
#rs2="$rs2 <tr><td>$loop</td></tr>"
#done


echo "$rs $rs2</table><br><br>" >> $export_html
#echo "$rs $rs2</table>" > /var/www/html/shell_email.html
#IFS=$IFS_old




##### ================jslint

log_xml="/var/www/html/jslint/out/data/log.xml"

#多少报错文件
file_num=$(awk -F \" '{if($1~/<Violation/) print $8}' $log_xml | grep -v "js_all.js" | un