"script" Command Problem

Anyone know how to make the output of command

# script

show standard text as seen on the actual CLI? I’m trying to log my bash sessions so that if I run into problems I can easily copy and paste my i/o to forums or my blog but when I open up the created .txt files I’m seeing what I assume are codes for keystrokes. I’ll give an example:


# script -a "/srv/Server/bashscripts/test1.txt"
Script started, file is /srv/Server/sashscripts/test1.txt
# echo "Hi there, this is just a test"
Hi there, this is just a test
# exit
Script done, file is /srv/Server/bashscripts/test1.txt

shows an output of:

Script started on Sun Aug 21 22:51:25 2011
1m31mlinux-ki7e:/dev # 0;10mecho “Hi there, this is just a test”
Hi there, this is just a test
1m31mlinux-ki7e:/dev # 0;10mexit

Script done on Sun Aug 21 22:51:38 2011

when I open up test1.txt. I thought maybe it was because I’m outputting to a text file (I’m viewing the files from a Windows box on my network) but outputting to an extension-less file returns the same thing. I’ve looked through the man pages for “script” but it says nothing about this. Is there a way to make it return characters as displayed? Am I making a mistake that is causing this to happen? Any advise would be much appreciated!

It is what is displayed. script captures everything that goes to the tty, including any terminal control characters. Those 1m, etc are ANSI escape sequences. You also get the CRs at the ends of lines in the file.

So is there a quick way to weed them out? I’ve been messing around with

# tr

with no luck yet…

You could set your terminal type within the script session to the dumbest possible one, but you’d still get things like backspaces and CRs. You might be able to remove those with judicious use of col and tr.

If you display that output in a terminal, then those sequences are probably interpreted by the terminal and should display okay.

I normally use “less” in an xterm to look at “typescript” files.

Very true, but I’m trying to access the file via Windows in the form of a .txt so I can just copy and paste my commands into a browser. I think I’m going to end up writing a bash script to do this but to be honest I’m not familiar enough yet with that process to know where to begin. I’ve just started reading the Linux Command Line and Shell Scripting Bible though so hopefully soon I’ll feel confident enough to do this.

The strange characters that are in the “typescript” file are escape characters. The definition of the escape characters depends on the terminal characteristics. They are probably for either type “xterm” or type “linux”, as set by $TERM in the session where script was run. When you use “less” as suggested, that has access to the same terminal characterists table for interpreting the escape characters. There are probably sed scripts available that just strip them out, at least for variants of the “vt100” and “ansi” terminal definitions.

The easiest thing would have been to browse the typescript file while still running linux, then while browsing use copy/paste to copy into a plain text file that you could then use on Windows.

On the other hand, there is probably a “less” available for Windows, though that might require installing CYGWIN.