我是Unix命令的新手,想知道下面做的脚本。
采取的步骤: 我已经使用grep读取了关键字错误并写入单独文件的文件。 给予文件许可。
感谢您的帮助。
代码段:
#!/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
答案 0 :(得分:0)
我无法写出完整的剧本,因为我并不完全清楚你想要什么,但这是一个策略。
所以,你最终会得到这样的东西:
grep ERROR /shipmentService/apache-tomcat-7.0.33/logs/catalina.out | cut -d ' ' -f4 | sort | uniq -c | mail -s "This is the subject" mail@example.com