awk分析处理jenkins的log文件并生成HTML文件
?
?
?
#!/bin/basha=$1##### ================pmdlog_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>"#doneecho "$rs $rs2</table><br><br>" > $export_html#echo "$rs $rs2</table>" > /var/www/html/shell_email.html#IFS=$IFS_old##### ================checkstylelog_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)#多少errormess_num_error=$(awk '/severity="error"/{line++}END{print line}' $log_xml)#多少warningsmess_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>"#doneecho "$rs $rs2</table><br><br>" >> $export_html#echo "$rs $rs2</table>" > /var/www/html/shell_email.html#IFS=$IFS_old##### ================jslintlog_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" | uniq |wc -l)#多少message#mess_num=$(awk -F " '{if($1~/<Violation/) print $2,$6,$8,$9}' /var/www/html/jslint/out/data/log.xml | grep -v "js_all.js" |wc -l)mess_num=$(awk '/<Violation/{line++}END{print line}' $log_xml | grep -v "js_all.js")#详细列表rs="<table border="0" cellpadding="0" width="100%"><tr><td height="22" class="bg1" colspan="6"><p style="color:#FFFFFF"><strong>JSlint Result (files:$file_num messages:$mess_num)</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">reason</td><td height="22" bgcolor="#4040FF">File</td><td height="22" bgcolor="#4040FF">code</td></tr>"#rs2=$(awk -F " '{if($1~/<Violation/) print "<tr><td>"$4,"</td><td>",$6,"</td><td>",$9,"</td><td>",$8,"</td></tr>"}' /var/www/html/jslint/out/data/log.xml |grep -v "<tr><td></td><td>" | grep -v "js_all.js")rs2=$(awk -F'"' '/Evidence/{gsub(/\/\/.*/,"",$2);gsub(/_/,"/",$8);sub(/>/,"",$9);sub(/<\/Violation>/,"",$9);sub(/\/var\/www\/html\//,"",$8);print "<tr><td>",++i,"</td><td>",$4,"</td><td>",$6,"</td><td>",$9,"</td><td>",$8,"</td><td>",$2"</td></tr>"}' $log_xml )#IFS_old=$IFS#IFS=$'\n'#for loop in $aa#do#rs2="$rs2 <tr><td>$loop</td></tr>"#doneecho "$rs $rs2</table>" >> $export_html##### ================gjslintlog_xml="/tmp/gjslint.log"/bin/touch $log_xmlif [[ $a = gjslint ]] ;then/usr/bin/gjslint -r /var/www/html/yii/blog/www/js/ > $log_xmlfi#多少报错文件file_num=$(awk '/-----/{line++}END{print line}' $log_xml)#多少messagemess_num=$(awk '/Line/{line++}END{print line}' $log_xml )#详细列表rs="<table border="0" cellpadding="0" width="100%"><tr><td height="22" class="bg1" colspan="3"><p style="color:#FFFFFF"><strong>gjslint Result (files:$file_num messages:$mess_num)</strong></p></td></tr><tr><td height="22" bgcolor="#4040FF">No</td><td height="22" bgcolor="#4040FF">File</td><td height="22" bgcolor="#4040FF">Message</td></tr>"rs2=$( awk -F \: '/-----/{gsub(/-----/,"",$2);gsub(/\/var\/www\/html\//,"",$2);a=$2} /Line/{print "<tr><td>",++i,"</td><td>",a,"</td><td>",$0,"</td></tr>"}' $log_xml )echo "$rs $rs2</table><br><br>" >> $export_html?
?