简体   繁体   English

ssh 管道命令错误

[英]ssh pipeline command error

I am running on a machine我在一台机器上运行

ssh root@lPServerHgl  cat /root/devops/giveAllArtifacts.txt | xargs -I {} sh -c "grep {} /ci/test.log;"

I am getting grep: /ci/test.log: No such file or directory我得到 grep: /ci/test.log: No such file or directory

but the same command( cat /root/devops/giveAllArtifacts.txt | xargs -I {} sh -c "grep {} /ci/test.log;" ) on the server:lPServerHgl is working as it should without any error.但是服务器上的相同命令( cat /root/devops/giveAllArtifacts.txt | xargs -I {} sh -c "grep {} /ci/test.log;" )正在正常工作,没有任何错误。

PS ssh connection doesn't have any problems.All other commands are working over ssh.There seems to be some problem with piped commands. PS ssh 连接没有任何问题。所有其他命令都在 ssh 上工作。管道命令似乎有些问题。

The pipe is running on your local computer, not on the remote server.管道在您的本地计算机上运行,​​而不是在远程服务器上。

ssh user@host remote-cmd [...args] | local-cmd [...args]
--------- runs in server --------- | --- runs locally ----

The pipe is interpreted by your shell, not the remote one.管道由您的外壳解释,而不是远程解释。 To execute a pipeline on the other side of the ssh connection, you have invoke a shell there.要在ssh连接的另一端执行管道,您需要在那里调用一个 shell。 For example:例如:

ssh user@host bash -c "'cat file.txt | grep foo'"

Note the inner quotes.注意内部引号。 This will send the pipeline to a bash process on the other machine.这会将管道发送到另一台机器上的bash进程。

Typing these commands can be troublesome and bug-prone.键入这些命令可能很麻烦且容易出错。 You may want to place a ready-to-run script on the remote machine, to call it with a single command.您可能希望在远程机器上放置一个准备运行的脚本,以使用单个命令调用它。

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

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