Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1001025
  • 博文数量: 327
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4319
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 11:21
文章存档

2011年(31)

2010年(139)

2009年(157)

我的朋友

分类: LINUX

2010-10-28 14:46:33

script 真是一个神奇的小家伙,别看它小不起眼,可是却足够的好玩。script 能够将终端的会话过程录制下来,然后使用 scriptreplay 就可以将其录制的结果播放给他人观看。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 查询。

===================================================================================
 
Most sys admins know the importance of keeping an action log where various tasks, configuration changes, etc. are kept. Simple logs indicating, "I did this" or "John did that" may be sufficient in some organizations, but for some, full transcripts of changes made are desired. Doing a copy-and-paste of terminal output can be tedious at best, so one answer is to use a little-known program called script, which is part of the util-linux package on most Linux distributions.
script records everything in a session: things you type and things you see. It even records color; so if your command prompt or program output contains color, script will record it.
To use script, simply execute:
$ script
By default, it writes to a file called typescript in the current directory. From  then on, everything you type will be recorded to that file. To write to a  different file, simply use script /path/to/file.
When you're done, type exit. This will close down the script session and save the file. You can now examine the file using cat or any other program.
The downside of using script is the fact that it records all special characters, so your output file will be full of control characters and ansi escape sequences. This can be avoided by using a very Spartan shell with script:
 
$ SHELL=/bin/sh PS1="$ " script
 
When using script, don't use interactive programs or programs that manipulate the screen, like vi or top. They will ruin the output of the session. Otherwise, any command line programs you use and the steps you take to accomplish a task will be recorded. If you do need to edit a file in the transcript, consider exiting the script session and restarting it after the file edit with script -a, which will append the new session to the old session. 
 
=================================================================
 
阅读(808) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~