3

I am trying to log a terminal with the

ssh user@ip | tee -a test.log 

command. But, when I push backspace it prints in the log like:

pwe[J[J[Jexit

(for example). Is there any specific option that i can erase the backspace, etc chars and write only what I type in the end?

  • I get a \b (backspace) character, the output is not too surprising, it has a lot of control characters in it, to control the terminal, including \n already being converted to \r\n. There must be a way to turn off this filter. – ctrl-alt-delor Jul 14 '16 at 9:49
  • Ok, but how i avoid all these unnecessary prints in my log file? – user178591 Jul 14 '16 at 9:53
  • There is the -T option to ssh, but this in intended for non interactive mode. You will not see any prompts, and the log will only contain strict output. e.g. echo hello will log hello. – ctrl-alt-delor Jul 14 '16 at 9:58
  • 2
    When I do cat test.log it looks fine. But if in inspect the file with od I see the various control characters. (this will be a problem if you want to put the data through filters). – ctrl-alt-delor Jul 14 '16 at 10:03
  • 1
    That's exactly my point. i want to process data afterwards. So, any suggestions? – user178591 Jul 14 '16 at 10:09
1

You can use script instead of | tee ... script is tool for capturing user's output, so no need to invent anything new and I believe this should be resolved there.

To use script for ssh only you can use:

script -c "ssh ip@host" your.log

or create (a stupid) function:

function sssh() { script -c "ssh $1" $2 }
sssh ip@host your.log
  • the problem with script is that it doesn't update "live" like | tee command. And it writes the result after you close the terminal. I want to see the result live. But still, the problem remains with script command. Already tested it. – user178591 Jul 14 '16 at 11:08

Your Answer

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