简体   繁体   English

Windows日志文件的实时尾部

[英]Live tail of Windows log file

I have several Windows servers that I want to monitor a log file on them live and when a new line added with specific string to run a command on Linux server. 我有几台Windows服务器,它们想实时监视它们上的日志文件,以及何时添加带有特定字符串的新行以在Linux服务器上运行命令。

In order to tail the Windows log file I'm using the following command: 为了整理Windows日志文件,我使用以下命令:

Get-Content <file name> -Wait | Select-String -Pattern <some string>

The command prints, all lines that having the string and new lines having the string. 该命令将打印包含字符串的所有行和包含字符串的新行。

How can I show just new lines from the moment I run the command and not all lines on the files ? 从运行命令的那一刻起,如何显示新行,而不显示文件中的所有行?

I solved the issue by running the following command: 我通过运行以下命令解决了该问题:

get-content <file> -wait -tail 1 | select-string -pattern "<string>"

but need to make sure first that running it from PS V. 4 但首先需要确保从PS V运行它。4

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM