I have a coworker who was gripping the log file on one system, redirecting the output into a file, and then using sftp to put the file on a server. He asked if it was possible to simply redirect his output directly to another system.

I tried various ideas using scp:

$ cat .profile | scp qazwart@server2   # Nope didn't work
$ cat .profile | scp - qazwart@serer2  # Told me "-" doesn't exist

I had no better luck with ssh or sftp.

Is there a way to redirect output of a process from one system to a file on another remote lsystem?


Quite simple:

cat .profile | ssh qazwart@server2 "cat > ~/.profile"

The remote SSH command will take as stdin whatever you pipe from your local machine. You can do this with any other command, too. See some examples on this blog post and this Unix & Linux post.

  • 1
    A dangerous example.... – MariusMatutiae Aug 5 '14 at 6:19
  • Of course, but it's what the OP wants to use. – slhck Aug 5 '14 at 6:20
  • Of course, ssh! It does take STDIN. @MariusMatutiae - Yup, this is dangerous, but it does show this is possible. – David W. Aug 5 '14 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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