使用 script 录制终端会话

script 真是一个神奇的小家伙,别看它小不起眼,可是却足够的好玩。script 能够将终端的会话过程录制下来,然后使用 scriptreplay 就可以将其录制的结果播放给他人观看。script 的好处就在于,你在终端中的所有操作过程,它都可以原原本本地进行录制。试想一下,我们可以将这种录制应用在很多方面,诸如教学、演示等等。

script

一般来说,script 和 scriptreplay 在 Linux 发行版中都有默认安装。如果你打算使用 script 开始录制终端会话,可以敲入下列指令: script -t 2>demo.timing -a demo.session

该指令中的 -t 选项指明输出录制的时间数据,而 -a 选项则输出录制的文件。你可以将指令中的 demo 换成自己设置的名称。当终端中返回“Script started, file is demo.session”的信息时,你就可以进行需要录制的操作了。

如果需要结束录制过程,则输入 exit 即可。

要播放已录制完成的终端会话,可以使用指令:scriptreplay demo.timing demo.session

关于 script 及 scriptreplay 的更多信息,可以使用 man script 或 man scriptreplay 查询。

[via]

Read More:

13 Comments

  1. 1 cottage Commented @ 2007-05-09 9:53Reply to this comment

    真神奇!

  2. 2 bbbush Commented @ 2007-05-09 11:12Reply to this comment

    这个太有意思了

  3. 3 pig345 Commented @ 2007-05-09 13:57Reply to this comment

    好东西,估计这样的小玩意儿,linux各发行版的基础安装包里面有不少。 希望有了解的各位给多多介绍下哈。

  4. 4 weipipi Commented @ 2007-05-09 14:18Reply to this comment

    我只能用script -t 2>demo.timing -a demo.session,没有scriptreplay,难道要安装?

  5. 5 iveney Commented @ 2007-05-09 15:25Reply to this comment

    太好玩了~~~

  6. 6 左倾45度 Commented @ 2007-05-09 15:55Reply to this comment

    不错不错,以后就不用复制粘帖了呵呵

  7. 7 LiangXu Wang Trackbacked @ 2007-05-09 15:59Reply to this comment

    使用script录制终端会话...

    转自linuxtoy 英文出处在这儿 ubuntu feisty默认是安装的。 script 真是一个神奇的小家伙,别看它小不起眼,可是却足够的好玩。script 能够将终端的会话过程录制下来,然后使用 scriptreplay 就可以.....

  8. 8 huang Commented @ 2007-05-09 18:33Reply to this comment

    嗯,播放是不依赖于系统命令的,只要是一个支持ANSI控制码的终端就能再现; 要求播放终端的大小和录制终端的大小一致,否则可能会出现显示偏差; 显示的内容完全存放在demo.session中,辅以demo.timing中的时刻和控制操作来在屏幕显示; 甚至可以录制vim的编辑过程,在没有(或者配置不同的)vim的机器上也能完美再现编辑操作的过程; 多好的命令啊。。。

  9. 9 lewbing Commented @ 2007-05-10 13:18Reply to this comment

    scriptreplay是一个perl文件。直接从官方下载它的包 ftp://ftp.kernel.org/pub/linux/utils/util-linux/util-linux-2.12r.tar.bz2,将其解压缩后,find . -name \'scriptreplay.pl\'就可以找到了,将它放到系统目录即可直接运行了,前提是你安装了perl,我想一般的linux中都有perl这个软件包。 我用的是Archlinux系统,它装了util-linux,有script命令,但是没有scriptreplay命令。

  10. 10 mysurface Commented @ 2007-05-11 19:54Reply to this comment

    It works to record on ncurses application too. Cool!

  11. 11 Nothing to do But Ubuntu » Blog Archive » 使用 script 录制终端会话 Pingbacked @ 2007-11-13 22:27Reply to this comment

    [...] source:http://linuxtoy.org/archives/ record-terminal-session-with-script.html [...]

  12. 12 xiaohu417 Commented @ 2009-07-13 5:33Reply to this comment

    script 录制的数据文件和时间戳文件是独立的两个文件,这在实际生产中使用并不方便,有另外一个工具叫做 ttyutils,也可以完成 script 的功能,但是录制的文件只有一个,并且是加密和压缩的。ttyutils 的站点为 http://www.ttyutils.org

  13. 13 xiaohu417 Commented @ 2009-07-13 5:36Reply to this comment

    推荐一个 script 的图形播放器 ttyplayer,可以在 http://www.ttyutils.org 网站下载