我對Unix命令非常陌生,並且想知道下面的操作腳本。監視應用程序日誌並提取錯誤計數
- 需要閱讀應用程序日誌並在過去的半小時內拉出所有錯誤。
- 獲取每個錯誤的唯一計數。
- 將錯誤計數郵寄給團隊。
已採取的步驟: 我已經使用grep for關鍵字錯誤讀取文件,並將其寫入單獨的文件。 給予文件許可。
感謝您的幫助。
代碼段:
#!/bin/sh
cd Service/apache-tomcat-7.0.33/logs
for file in catalina.out; do
grep "ERROR" $file >error.txt
done
chmod 0777 error.txt
抽樣日誌
2014-09-03 16:45:36,814 ERROR xxxService: Could not find tool with id 365 intable:
2014-09-03 16:45:56,444 ERROR yyyService: summary counts not returned from accessor for xxxx, 1, mapParams
2014-09-03 16:45:56,444 ERROR yyyService: summary counts not returned from accessor for xxxx, 2, mapParams
2014-09-03 16:45:56,445 ERROR yyyService: summary counts not returned from accessor for xxxx, 3, mapParams
2014-09-03 16:45:56,445 ERROR yyyService: summary counts not returned from accessor for xxxx, 4, mapParams
2014-09-03 16:45:56,445 ERROR yyyService: summary counts not returned from accessor for xxxx, 5, mapParams
2014-09-03 16:46:00,077 ERROR yyyService: summary counts not returned from accessor for xxxx, 1, mapParams
2014-09-03 16:46:00,078 ERROR yyyService: summary counts not returned from accessor for xxxx, 2, mapParams
2014-09-03 16:46:00,078 ERROR yyyService: summary counts not returned from accessor for xxxx, 3, mapParams
2014-09-03 16:46:00,078 ERROR yyyService: summary counts not returned from accessor for xxxx, 4, mapParams
2014-09-03 16:46:00,079 ERROR yyyService: summary counts not returned from accessor for xxxx, 5, mapParams
2014-09-03 16:46:05,415 ERROR yyyService: summary counts not returned from accessor for xxxx, 1, mapParams
2014-09-03 16:46:05,416 ERROR yyyService: summary counts not returned from accessor for xxxx, 2, mapParams
2014-09-03 16:46:05,416 ERROR yyyService: summary counts not returned from accessor for xxxx, 3, mapParams
2014-09-03 16:46:05,416 ERROR yyyService: summary counts not returned from accessor for xxxx, 4, mapParams
2014-09-03 16:46:05,417 ERROR yyyService: summary counts not returned from accessor for xxxx, 5, mapParams
2014-09-03 16:46:59,881 ERROR yyyService: summary counts not returned from accessor for xxxx, 5, mapParams
2014-09-03 16:47:03,109 ERROR ErrorManager: 1409780823108: A General Exception Occurred
null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Error Message Count
ERROR xxxService: Could not find tool with id 365 intable: 1
ERROR yyyService: summary counts not returned from accessor for xxxx, 1, mapParams 3
ERROR yyyService: summary counts not returned from accessor for xxxx, 2, mapParams 3
ERROR yyyService: summary counts not returned from accessor for xxxx, 3, mapParams 3
ERROR yyyService: summary counts not returned from accessor for xxxx, 4, mapParams 3
ERROR yyyService: summary counts not returned from accessor for xxxx, 5, mapParams 4
ERROR ErrorManager: 1409780823108: A General Exception Occurred 1
請提供日誌文件的樣本輸出,包括一些線路是錯誤,還有一些不是。 – lxg 2014-09-04 19:14:59
@lxg:感謝您寶貴的時間閱讀我的疑問,並提供您現在需要的信息。再次感謝 – Vigneshwaran 2014-09-04 20:23:41
哪些信息表明錯誤的類型? (你說你想按錯誤類型對它進行分組。)是xxxService/yyyService列嗎? – lxg 2014-09-04 21:05:44