![Linux Shell Scripting Cookbook(Third Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/161/36701161/b_36701161.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
Start recording the terminal session with the following command:
$ script -t 2> timing.log -a output.session
A full example looks like this:
$ script -t 2> timing.log -a output.session # This is a demonstration of tclsh $ tclsh % puts [expr 2 + 2] 4 % exit $ exit
Note that this recipe will not work with shells that do not support redirecting only stderr to a file, such as the csh shell.
The script command accepts a filename as an argument. This file will hold the keystrokes and the command results. When you use the -t option, the script command sends timing data to stdout. The timing data can be redirected to a file (timing.log), which records the timing info for each keystroke and output. The previous example used 2> to redirect stderr to timing.log.
Using the two files, timing.log and output.session, we can replay the sequence of command execution as follows:
$ scriptreplay timing.log output.session # Plays the sequence of commands and output