I have aliases set up for SSH and minicom to call simple wrapper scripts which just ensure that I get a log of the session. The logs are stored in a specified directory, and named with a tag and a time-stamp so that I can find them again later.

For SSH the wrapper uses "script" to perform the session recording. For minicom the wrapper enabled the built-in session logging feature.

This works well for capturing simple output. However terminal control codes, can cause havoc with the legibility of the logs. In particular if I enter into vi, run "top", start "screen" use less to page up and down or even when "editing" the command line control characters end up in the captured log. "top" and "screen" contend for being the worst culprits in making these captured logs hard to read.

I've discovered that "more" is much better than "less" at viewing log files. More actually replays most of the control codes with a degree of success, resulting in something on screen which represents what was on screen originally.

Additionally "strings" (piped to more or less) or even more piped to less (less is more), can help to restore some sense to the log. grep can find a command ... if it was entered correctly and not been edited.

I'm looking for suggestions for viewing the logs, how to get rid of embedded control characters, and re-construct the terminal output as it was at the time it was captured as far as possible. GUI or CLI tools are both acceptable though I have a slight preference to using CLI tools.

I've been dabbling with the idea of writing a pre-processor script which will cut out "top". I also unfortunately quite often use screen to multiplex the sessions and save long running commands from being interrupted by a lost connection, so maybe I can find a way to recognize and strip out screen specific codes too.

  • As a start see serverfault.com/questions/71285/… which provides a sed script to strip ANSI escape codes. – PP. Jun 21 '13 at 11:16
  • It helps. Removes those peskty color-coded prompts and color coded output from ls.... but those were the least of my troubles. The escape codes involved in overdrawing (tm) the terminal are the most bothersome. – Johan Jun 21 '13 at 12:46

Your Answer

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

Browse other questions tagged or ask your own question.