假定我的系統日志 aa.log 經常會有這種錯誤提示,
***************************************************************
Error: >Sat Apr 11 16:16:37,406< RfcException:
message: Connect to SAP failed
**********************************************************
我的目標是出現此類 資訊 ,就將該日志檔案的此行后面的部分 ( 最新的錯誤資訊 ) 重定向到一個新的檔案(后面就是給管理員發郵件提示,比較容易了)
Error: >****** Date ****** ,406< RfcException:
#date
Sat Apr 11 16:18:16 CST 2020
我的方法是寫個定時監控腳本,假定每5分鐘監控一次。
root# grep Error aa.log | tail -4
Error: >Sat Apr 11 16:11:35,714< RfcException:
Error: >Sat Apr 11 16:13:22,223< RfcException:
Error: >Sat Apr 11 16:15:45,345< RfcException:
Error: >Sat Apr 11 16:17:35,714< RfcException:
難點在于:
1)如何定位到 當前5分鐘內 第一次出現 Error的行 ? 即 Error 后面的日期和現在的日期是 間隔在5分鐘內的(即剛剛發生的錯誤)
2)如何把該行后面的所有行重定向到一個檔案里?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/36139.html
標籤:專題技術討論區
上一篇:烏班圖系統下出現的例外
