快速截取某段时间内的日志

2018-05-25  本文已影响0人  桩i

在排除故障时,需要分析发生故障的原因,避免再次出现同样的问题,需要对日志进行分析,截取故障前后时间段的日志。

sed命令

sed -n ‘/2018-05-04 09:25/,/2018-05-04 10:00/p’  logfile        
2018-05-25 17:14:26,140 ERROR weaver.mobile.plugin.ecology.service.PushNotificationService  - лϢΆ̍ʧ°ڡ
2018-05-25 17:14:26,150 ERROR weaver.workflow.msg.notificationInteface.MobileNotification  - ready to push:[106], [], [·³ʺ(nҞv)F12-אӗ̼̘-nҞv-2018-05-25]
2018-05-25 17:14:26,150 ERROR weaver.mobile.plugin.ecology.service.PushNotificationService  - лϢΆ̍ʧ°ڡ
2018-05-25 17:14:26,150 ERROR weaver.workflow.msg.notificationInteface.MobileNotification  - ·¢̍·³͌⑑µ½¿ͻ§¶ʥ-message
2018-05-25 17:14:26,150 ERROR weaver.workflow.msg.notificationInteface.MobileNotification  - push to complete.
2018-05-25 17:14:26,341 ERROR weaver.system.GetPhysicalAddress  - weaver.system.GetPhysicalAddress
2018-05-25 17:14:35,751 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2961,log_nodeid=6221
2018-05-25 17:14:35,752 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2961,nodeId=6221,userId=375,language=7
2018-05-25 17:14:36,160 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4941
2018-05-25 17:14:36,160 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4941,userId=1587,language=7
2018-05-25 17:14:36,164 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4942
2018-05-25 17:14:36,164 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4942,userId=1587,language=7
2018-05-25 17:14:36,166 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4981
2018-05-25 17:14:36,166 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4981,userId=1587,language=7
2018-05-25 17:14:36,170 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4949
2018-05-25 17:14:36,170 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4949,userId=1587,language=7
2018-05-25 17:14:36,173 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4943
2018-05-25 17:14:36,173 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4943,userId=1587,language=7
2018-05-25 17:14:36,178 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4945
2018-05-25 17:14:36,178 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4945,userId=1587,language=7
2018-05-25 17:14:36,180 ERROR weaver.conn.RecordSet  - WorkflowViewSignMore.jsp  workflowId=2402,log_nodeid=4945
2018-05-25 17:14:36,180 INFO  weaver.odoc.workflow.workflow.utils.FormSignatureConfigUtil  - getFormSignatureConfig() workflowId=2402,nodeId=4945,userId=1587,language=7

awk命令

~]# cat ecology | awk -F, '$1 >="2018-05-25 17:10:36" && $1<="2018-05-25 17:14:36" ' >>/root/test0525.log

日志如上所示,逗号前是时间,所以我的awk的域分隔符是指定用逗号。然后取第一个区域,然后将搜索到的信息输出到文件。方便仔细查阅以及同事查阅。

上一篇下一篇

猜你喜欢

热点阅读