在錯誤日志log_errorhh.log log_errorhh.log.1中存在大量的重複不需要的日志 内容是:Request method 'HEAD'
#/bin/bash
#定義個時間變量
A=`date +%Y-%m-%d`
#複制錯誤日志到/opt/log/
cp /usr/local/tomcat_1/bin/log/log_errorhh.log /opt/log/
cp /usr/local/tomcat_1/bin/log/log_errorhh.log.1 /opt/log/
cd /opt/log/
#把兩個錯誤日志放到一個檔案中log_errorhh.log2
cat log_errorhh.log >> /opt/log/log_errorhh.log2
cat log_errorhh.log.1 >> /opt/log/log_errorhh.log2
#把重複的不需要的日志放到log_errorhh.log3
touch log_errorhh.log3
cat log_errorhh.log2 | grep "Request method 'HEAD' " >> /opt/log/log_errorhh.log3
#把重複的不需要的日志放到log_errorhh.log2
cat log_errorhh.log3 >> /opt/log/log_errorhh.log2
#對log_errorhh.log2 去重
sort log_errorhh.log2 |uniq -u >/opt/log/log_error$A
最後 log_error2017-07-06就是想要的錯誤日志
本文轉自 苑洪武 51CTO部落格,原文連結:http://blog.51cto.com/12927979/1945077