我有一些遗留软件需要在Control-M下自动化。这些工作属于Windows 2008R2。
如果这些作业运行正常,则它们的退出代码为0,但如果它们可以管理某些错误。当特定字符串在日志中时,我需要发出警报。
该字符串不在可执行文件的输出中。
我为此实施了另一项工作。它会搜索文件中的字符串,并在“On Do Actions”中搜索该语句。
要在输出中声明我认为使用类似 grep 的内容。我用过:
findstr
findstr "myerrorcode" D:\Log\greptest_%%$ODATE..log
grep
在这两种情况下,我都有相同的情况:
但问题是:当在文件中找不到字符串时,grep和findstr都返回代码= 1.
当文件无法打开且一切运行正常但是找不到日志中的sring时,如何判别案例?
答案 0 :(得分:3)
您应该能够使用grep
的退出状态来检测失败的原因。根据{{3}},退出状态部分:
EXIT STATUS The following exit values shall be returned: 0 One or more lines were selected. 1 No lines were selected. >1 An error occurred.
与POSIX grep
docs类似(一致,但更具体):
如果选择了一行,通常退出状态为0;如果没有选择行,则退出状态为1;如果发生错误,退出状态为2。 [...]其他grep实现可能会在出错时以大于2的状态退出。
例如,在bash
中,您可以使用case
命令来处理多个分支,如下所示:
#!/bin/bash
# search for error code in file
grep code file
# store the exit status in variable err
err=$?
# test several cases
case $err in
0) echo All good.;;
1) echo Code not found.;;
*) echo Error reading from file.;;
esac
答案 1 :(得分:0)
您可以轻松地在Control-M中处理此问题: 在“职位”选项卡中添加“操作”
字符串,长度为1到132个字符,包含作业脚本文件中的语句指定的字符串可以是语句的一部分。
语句字符串每个都可以包含掩码字符。有效 掩码字符是:
* – represents any number of characters (including no characters) $ – represents any single character ? – represents any single character
字符串,长度为1到255个字符 与操作系统对指定的响应相比较 言。
代码字符串每个都可以包含掩码字符。有效的面具 字符是:
* – represents any number of characters (including no characters) $ – represents any single character ? – represents any single character