首页 \ 问答 \ 如果日志文件有重复,请在日志文件中获取作业停机时间(Getting Job Downtime in a Logfile if it has a duplicate)

如果日志文件有重复,请在日志文件中获取作业停机时间(Getting Job Downtime in a Logfile if it has a duplicate)

我正在试图找出如何确定一个特定工作的相应重启时间(工作最后完成之前的最后一次重启)(异常终止)。

例如:

  • Job ABC在5:00运行
  • 工作ABC在5点03分退位
  • 它于5:05重新启动
  • 工作ABC在5:08再次出现
  • 它于5:10再次重新启动
  • 工作ABC于5:15完成

在这个例子中,我可以安全地假设首次运行在5:00的Job ABC的完成时间是5:15。 我正在尝试通过减去上次重新启动时间(5:10 - 5:03 = 7分钟停机时间)来计算Job ABC的停机时间。

这是我做的第一次失败和最后一次重启的时间:

grep abended logfile | head -1   #first failure
grep restarted logfile | tail -1 #last restart

但问题是,如果另一个Job ABC在6点运行呢?

说吧,

  • 另一个ABC工作时间是6点。
  • 它在6点03分消失了。
  • 它于6:05重新启动
  • 工作ABC于6:07完成。

如果是这种情况,我不能再使用我上面所述的头部和尾部了。

如何判断6:05的重启是否与6:03时首次出现的另一个Job ABC相对应?

顺便说一下,我正在尝试创建一个自动化工具来获取作业的停机时间,我唯一的参考是一个纯文本日志文件,每24小时自动创建一次。

注意:我正在使用Bash脚本。


I'm trying to figure out how to determine the corresponding restart time (the last restart before job finally completed) of a specific job that abended (abnormal termination).

For example:

  • Job ABC ran at 5:00
  • Job ABC abended at 5:03
  • It was restarted at 5:05
  • Job ABC abended again at 5:08
  • It was restarted again at 5:10
  • Job ABC completed at 5:15

In this example, I can safely assume that the completion time of Job ABC which first ran at 5:00 is 5:15. I’m trying to compute the downtime of Job ABC by subtracting the time it was last restarted from the first time it abended ( 5:10 – 5:03 = 7mins downtime).

This is what I did to get the first failure and the last restart time:

grep abended logfile | head -1   #first failure
grep restarted logfile | tail -1 #last restart

But the problem is what if another Job ABC runs at 6:00?

Let say,

  • Another Job ABC ran at 6:00.
  • It abended at 6:03.
  • It was restarted at 6:05
  • Job ABC completed at 6:07.

I can no longer use the head and tail I stated above if this is the case.

How can I tell if the restart at 6:05 corresponds to another Job ABC which first abended at 6:03?

By the way, I’m trying to create an automated tool that will get the downtime of a job and my only reference is a plain text log file which is auto created every 24hours.

NOTE: I'm using Bash script.


原文:https://stackoverflow.com/questions/16478855
更新时间:2023-05-24 15:05

最满意答案

所以你想要匹配一个非全点字符的字符串:

^[^.]*$

或者是非点字符的字符串,后跟a . ,后跟非点字符:

^[^.]*\.[^.]*$

我们可以将它们组合成一个正则表达式:

^[^.]*(?:\.[^.]*)?$

那是:

^         # beginning of string
[^.]*     # 0 or more non-. characters
(?:       # start of a (non-capturing) group
  \.      # a literal .
  [^.]*   # 0 or more non-. characters
)?        # end of group, which is optional (appears 0 or 1 times)
$         # end of string

So you want to match either a string that is all non-dot characters:

^[^.]*$

or a string that is non-dot characters, followed by a ., followed by non-dot characters:

^[^.]*\.[^.]*$

We can combine those into one regex:

^[^.]*(?:\.[^.]*)?$

That is:

^         # beginning of string
[^.]*     # 0 or more non-. characters
(?:       # start of a (non-capturing) group
  \.      # a literal .
  [^.]*   # 0 or more non-. characters
)?        # end of group, which is optional (appears 0 or 1 times)
$         # end of string

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。