1

I hope this makes sense. I use 'scripts' to make copies of my ssh sessions for various reasons.

When I access the logs via less, etc, I see this:

Script started on Mon 12 Sep 2011 08:59:14 AM CDT

ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# 
ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# logout
ESC[HESC[2JConnection to closed.^M
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from ^M
ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# 
ESC]0;     3.03, 2.32, 2.20^G
test.log (END) 

When I cat it, I see this:

Perk ~ # cat test.log 
Script started on Mon 12 Sep 2011 08:59:14 AM CDT

[root@ ~]# 
[root@ ~]# logout

Connection to closed.
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from 
[root@ ~]# [/code]

If I try and pipe this to a file, it returns to look like the less output.

When I edit it in vi, this is what i see:

Script started on Mon 12 Sep 2011 08:59:14 AM CDT
^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# ^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# logout^M
^[[H^[[2JConnection to closed.^M^M
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from ^M^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# ^M
^[]0;     3.03, 2.32, 2.20^G^M

Does anyone know how I can get this cat output into a file for easy viewing?

1
  • 2
    It works properly with cat because your terminal emulator interprets these caracters as colors for the text.
    – Lynch
    Sep 15, 2011 at 1:58

3 Answers 3

3

Instead of regular less, try:

less -R
2

Why don't you use script

script -t scriptfile > timingsfile

So you can

replay scriptfile

The timing are optional. In fact you could run replay |ansifilter to translate into, say, HTML etc.

to have the exact script replayed in real-time. I think this is much more apt as clearly you are trying to log interactive sessions (most Unix tools are aware of when they are not connected to a tty (batch mode, piped stdin/out), and already prevent emitting terminal codes in such cases)


There is also termrec which is able to control the playback speed. Nice for creating specific screenshots e.g.

1
  • Your script ... > timingsfile should be script ... 2> timingsfile to capture stderr (the timing data output) in timingsfile, rather than stdout. Also, note that JPerkSter already is using script. Sep 19, 2011 at 19:11
0

There is a command colcrt which strips terminal formatting codes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .