Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I can copy a file to a remote Linux machine with no problem with

scp file user@host: /pathtowrite_file

However, I'm having difficulty writing to a file from one linux machine to another. Here is what I attempted:

echo 'Some Text' > /remotefile.txt | ssh user@remotehost

The notice that I get is

stdin: is not a tty

At any rate, the file on the remote machine does not reflect the text sent 'Some Text'.

share|improve this question

1 Answer 1

up vote 19 down vote accepted

You can use the "cat" command to create the remote file.

echo 'Some Text' | ssh user@remotehost "cat > /remotefile.txt"
share|improve this answer
    
but, I want to write to the existing file on the remote machine. –  suffa Mar 14 '12 at 17:36
    
the "cat > /remotefile.txt" runs on the remote machine and if you want to append to a existing file you replace ">" by ">>" –  Aragorn Mar 14 '12 at 17:42
    
@suffa: Are you trying to append to an existing file? Or do you want to overwrite the file but fail if it doesn't already exist? Or what? –  David Schwartz Mar 14 '12 at 17:52
    
@ David Schwartz - either. I would like to overwrite, and fail if it doesn't exit ... but, I would take just appending at this point. –  suffa Mar 14 '12 at 19:06
    
` echo 'Some Text'|ssh user@remotehost "tee -a /remotefile.txt"` worked for me as well. –  Simply Seth Oct 13 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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