简体   繁体   English

如果 STDOUT 更改为我要查找的内容,则终止命令行进程并重新启动?

[英]Kill command line process and restart if STDOUT changes to what I'm looking for?

I have a question - I'm running a process from the command line that has some problem and poops out every few hours or so.我有一个问题 - 我正在从命令行运行一个有问题的进程,每隔几个小时左右就会出现一次。 While I'm looking into the issue, I'd like to spawn the process from something that monitors STOUT for certain string/regex and kills and restarts the process if it outputs something that indicates that it's broken.在我研究这个问题时,我想从监视 STOUT 的某些字符串/正则表达式的东西中生成该进程,如果它输出表明它已损坏的内容,则终止并重新启动该进程。

I know I could do this the vanilla way by rolling my own Python/Ruby script but I was wondering if there's any nifty tools I can use to make this a bit cleaner?我知道我可以通过滚动我自己的 Python/Ruby 脚本来以普通的方式做到这一点,但我想知道是否有任何漂亮的工具可以用来让它更干净一点? This is on Windows but I have cygwin in case the answer involves a unix command line process.这是在 Windows 上,但我有 cygwin,以防答案涉及 unix 命令行过程。

program |程序 | grep CRASH_STRING | grep CRASH_STRING | xargs -l 1 sh -c 'killall program && program' xargs -l 1 sh -c 'killall 程序 && 程序'

Well, that will do it once.好吧,那会做一次。 I'm not sure how to make that work in a loop.我不确定如何让它循环工作。 I thought about it some more, and it can probably be done by redirecting stdout to a named pipe.我想了更多,可能可以通过将标准输出重定向到名为 pipe 来完成。 But the shell script will probably end up more unwieldy than writing a watchdog in a scripting language.但是 shell 脚本最终可能会比用脚本语言编写看门狗更笨拙。

But the idea with a pipe is something like this:但是 pipe 的想法是这样的:

mkfifo /tmp/fifo
program > /tmp/fifo&
while :
do
grep "CRASH_STRING" /tmp/fifo | xargs -l 1 sh -c 'killall program && program > /tmp/fifo&'
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 bash:在其stdout中的正则表达式匹配时杀死子进程 - bash: kill child process upon regex match in its stdout 寻找awk命令在行尾添加文件名 - Looking for awk command to append filename at end of line 使用 bash 和正则表达式在一行中查找并终止进程 - Find and kill a process in one line using bash and regex 鼻框架命令行正则表达式模式匹配不起作用(-e,-m,-i) - nose framework command line regex pattern matching doesnt work(-e,-m ,-i) 使用命令行,如何获得每种类型的n种可能的结果? - Using command line, how do I get m out n possible results of each type? 在 c# 中,我正在寻找一个只匹配第一次出现的正则表达式 - In c# I'm looking for a regex that will only match the first occurrence 跳过我正在寻找的模式中包含的正则表达式模式 - Skipping over a regex pattern contained within the pattern I'm looking for 我想从Java中的匹配模式中提取值 - I'm looking to extract values from matched pattern in Java 替换单元格中除我要查找的字符串外的所有内容 - Replace everything inside a cell except the string I'm looking for 我正在寻找正则表达式以从匹配中排除特定的 substring - I'm looking for Regular expressions to exclude a specific substring from a match
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM