Reputation: 575
I have two files, file1
on server 1 and file2
on server 2.
Now I want to write a script to append the contents of file2
(from server 2) to file1
(on server 1), that is, without overwriting the original contents.
How can I do this with a shell script (using Ubuntu Linux)?
Upvotes: 0
Views: 3874
Reputation: 798536
ssh server2 "cat /path/to/file2" | ssh server1 "cat >> /path/to/file1"
If minimizing network traffic is an issue, use the trickier-to-quote version:
ssh server2 'cat /path/to/file2 | ssh server1 "cat >> /path/to/file2"'
The first version transfers the file to your local host, then to server1
. The second version transfers the file directly from server2
to server1
. (If either file path contains spaces, the quoting becomes much trickier.)
Upvotes: 5