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.

  • So... from Computer A you want to log into Computer B, and log output to Computer A? – Wilf May 20 '17 at 19:23
  • That is correct. – NonStandardModel May 20 '17 at 19:32

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
  • 2
    A slightly better way would be to use the tee command, so that you'd also see the output on the screen. For instance: ssh user@machine command | tee log – boardrider Aug 6 '19 at 17:21

If you want to see what are typing and output at the same time - try it:

ssh user@host 2>&1 | tee ssh-session.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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