简体   繁体   中英

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

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.

PS ssh connection doesn't have any problems.All other commands are working over ssh.There seems to be some problem with piped commands.

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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