44
13
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'.
echo 'Some Text'|ssh user@remotehost "tee -a /remotefile.txt"
worked for me as well. – Simply Seth – 2014-10-13T20:20:29.953@Aragorn I tried your command but got an permission denied after it. What could be the reason? I already tried it with sudo too – Jenson – 2016-01-28T15:50:35.147
@Jenson the file "/remotefile.txt" is in the root directory and in a normal system that is restricted to the root user – Aragorn – 2016-01-29T05:58:34.600
but, I want to write to the existing file on the remote machine. – suffa – 2012-03-14T17:36:21.913
2the "cat > /remotefile.txt" runs on the remote machine and if you want to append to a existing file you replace ">" by ">>" – Aragorn – 2012-03-14T17:42:56.053
@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 – 2012-03-14T17:52:08.523
@ 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 – 2012-03-14T19:06:59.697