script makes a typescript of everything displayed 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).
译文:脚本可以对终端上显示的所有内容进行排版。 对于需要交互式会话的硬拷贝记录作为作业证明的学生来说,它非常有用,因为排版稿文件可以在以后用 lpr(1) 打印出来。
1. script的-t参数
script OPTIONS
-t[file], --timing[=file]
Output timing data to standard error, or to file when given. 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.
- 根据手册,script -t参数能够:将定时数据输出到标准误差,或在给定时输出到文件。该数据包含两个字段,用空格分隔。第一个字段表示自上次输出以来经过了多少时间。第二个字段表示这次输出了多少个字符。此信息可用于重放具有真实输入和输出延迟的排版脚本。
- Emp:
script -trecord-time.tm shell-script.txt
这样会生成一个记录时间的文件record-time.sh(记录时间间隔)和一个shell-script.txt(记录输入和输出)的文件,如下:- record-time.sh
- shell-script.txt
- record-time.sh
2. scriptreplay
scriptreplay - play back typescripts, using timing information
OPTIONS
-t, --timing file
File containing script’s timing output.
-s, --typescript file
File containing script’s terminal output.
- Emp:
scriptreplay -t record-time.tm -s shell-script.txt
启动脚本后会自动回放执行的操作并具有当时输入输出时的延迟
3. 对于生成的shell-script脚本
- 当使用vim编辑时可能发现他是乱糟糟的,不要在意,那些只是对于字体高亮的一些格式字符,当使用cat将其打印到终端时,会自动解析这些符号
- 使用
script
时完全可以不使用-t参数,这样会得到同样的一个记录文件,同样可以用cat来复现操作