the-bastion icon indicating copy to clipboard operation
the-bastion copied to clipboard

Option to use `script` instead of `ttyrec`

Open DenisBY opened this issue 1 year ago • 2 comments

Is there a way to use script command instead of ttyrec? Or is there a way to convert a record into "plaintext"?

DenisBY avatar Jan 30 '25 10:01 DenisBY

Hello,

The ttyrec program is actually a fork and a superset of script, and their output format is very similar. The main change is that for ttyrec, there is timing info added in the output file, so that it can be replayed "at the same pace" that the captured console.

With both programs, the entire console output is captured, i.e. plaintext, but also control codes, such as "move the cursor here", "change the background color to this", etc. If you cat the output files of script or ttyrexc, you'll see plaintext but also these non-printable control-codes. It is not trivial to convert these to "real" plaintext because you have to interpret all the control codes correctly to reproduce the actual output.

For example, if I type "helk" then "backspace" then "lo", on my console, "hello" will be displayed when I'm done, but in the output files of both script and ttyrec, this is what will be written: helk^H^[[Klo. So grepping for "hello" inside these files will not work, even if you would have expected it to work.

This even gets more complicated for programs using curses such as vim, where you can navigate in a file: a lot of control codes are used to control what the console displays, and there is no way, from what is displayed in the console, to know what is part of the preexisting file, and what is being typed by the person. In both cases, it just ends up on the screen.

Now, some solutions exists. You might want to have a look to IPBT (It's Playback Time), which is an advanced ttyrec player from the author of PuTTY: https://www.chiark.greenend.org.uk/~sgtatham/ipbt/ . It has the option of actually grepping for a string inside a ttyrec, and it does this by rendering each "frame" in-memory, then actually looking for the output in the emulated console. This would work with the "hello" example above. Modifying this program a bit might permit dumping all the strings that appear on all frames.

EDIT: it seems that the author recently added an "ipbt-dump" program that might be of interest for your use case: https://git.tartarus.org/?p=simon/ipbt.git;a=blob;f=doc/man-ipbt-dump.but;h=b2004cf0a925eac08c65448701ffd64e4f6a7eb3;hb=bc876eaf74939d3e7b255ac6c2d10c8d8f5fe276

speed47 avatar Feb 04 '25 09:02 speed47

Thank you for such detailed explanation!

DenisBY avatar Feb 04 '25 16:02 DenisBY

Added as FAQ https://ovh.github.io/the-bastion/faq.html#can-the-bastion-record-sessions-with-script-or-in-plaintext-format-instead-of-ttyrec

speed47 avatar Sep 11 '25 15:09 speed47