Using "script"
From DSL Wiki
If you want to capture the output from a command line session you might like to use the script command.
dsl@box:~$ script Script started, file is typescript dsl@box:~$ date Wed Jan 19 15:26:43 EST 2005 dsl@box:~$ Script done, file is typescript
You hit CTRL+D to stop the recording and you will find a file called 'typescript' in the local directory that contains a log of what was recorded.
If you want to be able to replay these files then you need to record timing information as well as the typescript. Use the -t option to do this...
dsl@box:~$ script -t 2> timing.log Script started, file is typescript dsl@box:~$ date Wed Jan 19 15:26:43 EST 2005 dsl@box:~$ Script done, file is typescript
You will see 2 files in the local directory; typescript and timing.log. You can now playback the files in realtime using the 'replay' command...
replay timing.log typescript