如果日志文件有重复,请在日志文件中获取作业停机时间(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
最满意答案
所以你想要匹配一个非全点字符的字符串:
^[^.]*$
或者是非点字符的字符串,后跟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
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
所以你想要匹配一个非全点字符的字符串: ^[^.]*$ 或者是非点字符的字符串,后跟a . ,后跟非点字符: ^[^.]*\.[^.]*$ 我们可以将它们组合成一个正则表达式: ^[^.]*(?:\.[^.]*)?$ 那是: ^ # beginning of string [^.]* # 0 or more non-. characters (?: # start of a (non-capturing) group \. # a literal . ...
-
您提供的正则表达式只匹配您尝试验证的整个字符串中的单个字符。 在您的方案中有几件事需要处理 您希望匹配整个字符串,因此您的正则表达式必须以^开头(字符串的开头)并以$结尾(字符串的结尾)。 然后你想接受任意数量的字母数字字符,这是用[a-zA-Z0-9]+ ,这里+表示一个或多个字符。 然后匹配点: \. (你必须在这里逃避它) 最后再接受更多角色。 所有正则表达式将是: ^[a-zA-Z0-9]+\.[a-zA-Z0-9]+$ The regex you provided matches only a ...
-
我只会得到所有“非空间”字符: \s?(\w+)=(\S*)\s? FYI (\S*)与(\S+)?具有相同的效果(\S+)? ,但更简单。 I would just get all "non-space" chars: \s?(\w+)=(\S*)\s? FYI (\S*) has the same effect as (\S+)?, but is simpler.
-
好吧,这是我在正则表达式答案方面最好的,使用链式条件确保你只得到你想要的字符串(虽然它在我看来仍然非常不优雅): ^(.*)?S(?(1)|(.*))?p(?(2)|(.*))?e(?(3)|(.*))?c(?(4)|(.*))?i(?(5)|(.*))?f(?(6)|(.*))?i(?(7)|(.*))?(?(8)|(.*))?c(?(9)|(.*))?S(?(10)|(.*))?t(?(11)|(.*))?r(?(12)|(.*))?i(?(13)|(.*))?n(?(14)|(.*))?g(?(15) ...
-
字符串中链接的正则表达式,仅在行尾排除点(regular expression for links in string to exclude dot only at end of line)[2023-07-12]
将您的RegEx更改为此 \b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[A-Z0-9+&@#/%=~_|!:,.;]*)? 或这个 \b((?:https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]*)\b 说明 " \b ... -
从您之前的问题 ,您应该能够使用: ^[^.].*[^-_.]$ 但是,如果您希望能够匹配1个字符的字符串,则需要使用否定前瞻: ^(?![.])(?!.*[-_.]$).+ 如果你想匹配空字符串,只需使用*而不是+ 。 ^(?![.])(?!.*[-_.]$).* From your previous question, you should be able to use: ^[^.].*[^-_.]$ But if you want to be able to match a 1 charact ...
-
量词只修改它们旁边的原子(子模式)的行为。 此外,由于您将所有子模式序列放入字符类,因此您的正则表达式已“破坏”。 你可以用 /^(?!.{11})[a-z]+(?: [a-z]+)?$/ 请参阅正则表达式演示 如果char可以是任何非空白字符,请将[az]替换为\S 说明 : ^ - 字符串的开头 (?!.{11}) - 如果从字符串的开头找到任何11个字符,则不返回匹配项(此负面预测将与(?=.{1,10}$) - 任何1到10个字符到字符串结尾) [az]+ - 1+小写字母(替换为您真正允许的内容 ...
-
在\.[0-9]旁边添加重复或范围量词。 ^[0-9]+(\.[0-9]{1,2})?$ [0-9]{1,2}应匹配一位或两位数。 Add repeatation or range quantifier next to \.[0-9].. ^[0-9]+(\.[0-9]{1,2})?$ [0-9]{1,2} should match either one or two digits.
-
溢出的字符串与点但不在于单引号使用jquery或正则表达式(spilt string with dot but dot not lies in single quote using jquery or regex)[2023-04-04]
你可以匹配下面的正则表达式: /[^.']+(?:'[^']*')?/g 查看正则表达式演示 细节: [^.']+ - 除'和”以外'一个或多个字符. (?:'[^']*')? - 一个可选的'...'字符串( '后接'以外'字符,后跟' 。 根据内容的不同,您可以使用增强版本: /[^.']*(?:'[^']*'[^.']*)*/g 看另一个演示 演示1(简化): var re = /[^.']+(?:'[^']*')?/g; var str = '12:\'xyz@gmail.com\'.8:\ ...