Ubuntu: How to redirect command output from remote machine to local file via ssh?



Question:

Example: I log on my laptop machine (Ubuntu 14.04) via ssh and I need to make a .log file of some command output and than transfer it to my desktop machine. The command has -o option to redirect the output to a file. I could than just copy the file with scp command.

The question is: Can redirect the output directly to my machine, without the need to first make a file on laptop and than transfering it with scp?

Both machines use Ubuntu 14.


Solution:1

Depend on your command you can do something like this:

ssh user@machine command > log  

the log will be saved in your machine, a real example:

ssh root@192.168.x.x ls > log  

If your command does not supports outputs to stdout then run it like this:

ssh root@192.168.x.x "command -o output; cat output"  > log  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »