How to redirect the output of a unix command from one server to another server.
I should be able to send the unix command's output from server-1. Then I should be able to receive the output in Server-2 and write it into a file.
How to redirect the output of a unix command from one server to another server.
I should be able to send the unix command's output from server-1. Then I should be able to receive the output in Server-2 and write it into a file.
General, you can always do:
<command> | ssh user@remote-server "cat > output.txt"
It saves output of <command>
to output.txt
file in remote server.
In your case, on Server-1:
echo "qwerty" | ssh user@Server-2 "cat > output.txt"
If two servers have no connectivity, but you can ssh to both servers, then from local machine, you can do:
ssh user@Server-1 "<command>" | ssh user@Server-2 "cat > output.txt"
You can run:
ssh remote_server "command" > file_on_local_host.txt
or use the output as an input for local command:
ssh remote_server "remote_command" | local_command
Since you can't connect directly from server 1 to server 2 you can use this, having your local machine in the middle:
ssh server1 command | ssh server2 "cat > output.txt"