linux下用script和scriptreplay对命令行操作录像

来源:互联网 发布:淘宝网店取名 编辑:程序博客网 时间:2024/05/21 06:32

Linux下有个神奇的命令script可以实现对命令行操作的过程进行录像和回放,对记录或者教学有很大帮助。

在要记录操作之前输入命令:

[root@localhost ~]# script -t 2> test.time -a test.txtScript started, file is test.txt[root@localhost ~]#

这个时候你再输入的命令都已经被记录在test.txt这个文件里面了,
如果想停止录像的时候

[root@localhost ~]# exitexitScript done, file is test.txt[root@localhost ~]#

候看当前目录下就有2个文件了,一个是test.time 另一个是test.txt
test.time就是记录的时间数据,test.txt记录就是操作记录,当然,这两个文件的名称和路径,我们可以任意指定。
我们可以cat一下test.txt这个文件,可以看到刚才操作的记录

说明: -t 2>test.time -t是把时间数据输出到标准错误(standard error)
所以我们使用 2>test.time 把数据转向到 test.time这个文件当中

这个只是可以看到,那我们怎么播放这个记录呢?
就要用到scriptreplay这个命令了
默认的系统里面是没有scriptreplay这个命令的,如何安装呢,其实这个脚本是一个pl脚本,
在util-linux这个包里可以找到它

[root@localhost ~]# wget http://dxdown.onlinedown.net/down/util-linux-ng-2.17.2.tar.zip[root@localhost ~]# unzip util-linux-ng-2.17.2.tar.zip[root@localhost ~]# tar zxvf util-linux-ng-2.17.2.tar.gz[root@localhost ~]# cd util-linux-ng-2.17.2[root@localhost ~]# ./configure && make (注意此处只是make了)[root@localhost ~]# cp misc-utils/scriptreplay /usr/bin/[root@localhost ~]# cd ..[root@localhost ~]# rm -rf util-linux-ng-2.17.2*

这个时候就可以用scriptreplay这个命令来播放刚才的录像了

[root@localhost ~]# scriptreplay test.time test.txt

就可以播放了
不过,我们在播放“录像”的时候,要注意那两个“时间文件”和“命令文件”的顺序,不要颠倒了。

有了这个,以后做教程什么的,录像之后,把两个文件发给别人,别人就直接可以看了,很方便的说。

原文固定链接: http://www.linuxyan.com/web-server/28.html

0 0
原创粉丝点击