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.
P.S 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With