A client recently asked if there was a way we could output a terminal session to a file; in researching this more, I am seeing three ways:
script -f log.txt
script [-a ] [-f ] [-q ] [-t ] [file ]
Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file If no file name is given, the typescript is saved in the file typescript
-a Append the output to file or typescript retaining the prior contents.
-f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo’ and another can supervise real-time what is being done using `cat foo’.
-q Be quiet.
-t Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays.
The script ends when the forked shell exits (a control-D to exit the Bourne shell ( sh(1)) and exit , logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)).
is a reimplementation of script(1) with a little more functionality thrown in. It should be a drop in replacement for traditional use (right down to interoperating with scriptreplay(1))
Logging Your Screen Output
Using the Screen command makes this easy as well.
Using “Ctrl-a” “H”, Begin/end logging of the current window to file “screenlog.n”
Screen will keep appending data to the file through multiple sessions. Using the log function is very useful for capturing what you have done, especially if you are making a lot of changes. If something goes awry, you can look back through your logs.