#!/bin/bash
DATA1=`date -d '1 days ago' +%d/%b/%Y`
DATA2=`date +%Y%m%d`
FILE1='api.example.com-https.log'
TO='manager1@example.com manager2@example.com'
echo "URL MaxTime AveTime TotalRequests" > ${FILE1}_url_groupby.log &&
zcat /server/logs/nginx/$FILE1-$DATA2.gz|grep "$DATA1"|sed 's/\xA0/ /g'|tr -d '['|tr -d ']'|awk '{print $10,$6}'|awk -F"?" '{print $1}'|awk '{m[$2]=m[$2]>$1?m[$2]:$1;s[$2]+=$1;c[$2]+=1}END{ for(i in s){print i,m[i],s[i]/c[i],c[i]} }'|sort -k3 -r -n >> ${FILE1}_url_groupby.log &&
echo "<html>" > email.html
echo "<Body>" >> email.html
awk 'BEGIN{print "<table border=\"1\">"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' ${FILE1}_url_groupby.log >> email.html
echo "</Body>" >> email.html
echo "</html>" >> email.html
sendEmail -o tls=yes -f auto@example.com -t ${TO} -s smtp.exmail.qq.com:587 -xu auto@example.com -xp password -u "hostname01_$FILE1-$DATA1" -o message-content-type=html -m "`cat email.html`"