use*_*610 1 powershell logstash
我们有脚本通常在unix环境中执行.以下是脚本中的一行:
command => 'use/bin/tail -n 1 %{path} | grep --silent -F "%{message}" && rm -f {path}'
Run Code Online (Sandbox Code Playgroud)
在PowerShell中运行时,use/bin/tail显然无法识别路径.作为替代方案,我试过这个:
command => 'Get-Content -n 1 %{path} -Tail | grep --silent -F "%{message}" && rm -f {path}'
Run Code Online (Sandbox Code Playgroud)
但是,虽然Get-Content从PowerShell命令行本身运行时可以识别,但在脚本中运行时无法识别.这是错误消息:
"Get-Content"不被识别为内部或外部命令,可操作程序或批处理文件.
tail在PowerShell中运行脚本时,复制unix 命令的正确方法是什么?
您收到的错误:
%1 is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
是标准错误cmd.exe,而不是powershell.exe:
您的命令不是由PowerShell主机执行,而是由常规命令提示符执行 - PowerShell会提到在"未找到命令"的情况下调用"cmdlet,函数,脚本文件或可操作程序"的可能性(拼写错误的Get-有意展示的内容):

您还需要更多地编辑命令,以便PowerShell理解它,管道中的第一个语句将是:
Get-Content $Path -Tail 1
Run Code Online (Sandbox Code Playgroud)
假设它$Path包含您正在拖尾的文件的路径.
| 归档时间: |
|
| 查看次数: |
8006 次 |
| 最近记录: |