I want to redirect the output of a local command (using local files) to a remote command.


I know doing something like this is possible:

[user@local ~]$ head -c 5 /dev/urandom | ssh server@192.168.1.120 "cat"

... but I would like to know if there is a way to do this via the SSH console, just like the scp command that refers both local and remote files:

[user@remote ~]$ scp test.txt remote:/new.txt

Copying the local file to the remote server is undesirable, I would just like to redirect output.

** Both machines run Linux (bash).

link|improve this question

50% accept rate
feedback

2 Answers

This sounds similar to this question:

http://stackoverflow.com/questions/440524/ssh-a-way-to-transfer-files-without-opening-a-separate-sftp-session

So, it looks like the consensus is to set up an inverted ssh session with the -R option, and run the stdout through that.

link|improve this answer
feedback

I think the best way is to redirect the output to a file and then scp that file to the remote host and then you can run the cat command there.

$ head -c 5 /dev/urandom > random && scp ./random user@remoteip:/path/. && cat /path/random

Hope this will satisfy your needs. Reply if it don't.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.