我对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