欢迎光临
我们一直在努力

linux终端录屏与播放:script和scriptreplay

linux下script命令能够录制击键以及击键时机,并将输入和输出结果保存在对应的文件中;scriptreplay可以回放记录。这两个命令在绝大多数的GUN/Linux发型版上都可以找到,通过录制终端记录来制作命令行技巧视频,也可分享回话记录文件。另还可以调用其他解释器并录制发送给该解释器的击键。

srcript

说下常用的选项,更详细的说明可以man script来查看

选项 描述
-a, – -append 输出录制的文件,在现有内容上追加新的内容
-c, – -command 直接执行命令,而非是交互式的shell
-r, – -return 返回子shell的退出码
-f, – -flush 每次操作后都立即刷新缓存。 如果不设置这个选项,则不会实时写入文件
-q, – -quiet 可以使script命令以静默模式运行,不显示script启动和exit的命令,用户可以完全察觉不到在录屏
-t, – -timing[=<file>] 输出录制的时间数据,输出到屏幕或者存到指定文件中,回放的时候用到
-V, – -version 显示版本并退出
-h, – -help 显示使用说明并退出

scriptreplay

选项 描述
-t, – -timing file 包含记录时序的文件
-s, – -typescript file 包含脚本终端输出的文件
-d, –divisor number 加速播放速度倍数(可以是小数:放慢)
-V, – -version 显示版本并退出
-h, – -help 显示使用说明并退出

demo

录制文件

直接使用script命令,记录在默认文件中:typescript

[root@localhost ~]# script
Script started, file is typescript
[root@localhost ~]# pwd
/root
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# ./execShell.sh 
pwd:/root
date:Fri Jul 6 13:54:38 CST 2018
[root@localhost ~]# exit
exit
Script done, file is typescript
[root@localhost ~]# 
[root@localhost ~]# cat typescript 
Script started on Fri 06 Jul 2018 01:55:31 PM CST
[root@localhost ~]# pwd
/root
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# ./execShell.sh 
pwd:/root
date:Fri Jul 6 13:55:41 CST 2018
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 01:55:44 PM CST
[root@localhost ~]# 

再次执行script命令,文件typescript被重写

[root@localhost ~]# script
Script started, file is typescript
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# exit
exit
Script done, file is typescript
[root@localhost ~]# cat typescript 
Script started on Fri 06 Jul 2018 02:00:57 PM CST
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 02:01:03 PM CST
[root@localhost ~]# 

可以使用-a参数,记录追加在文件

[root@localhost ~]# script -a
Script started, file is typescript
[root@localhost ~]# echo "more"
more
[root@localhost ~]# exit
exit
Script done, file is typescript
[root@localhost ~]# cat typescript 
Script started on Fri 06 Jul 2018 02:00:57 PM CST
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  soft  typescript
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 02:01:03 PM CST
Script started on Fri 06 Jul 2018 02:02:07 PM CST
[root@localhost ~]# echo "more"
more
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 02:02:21 PM CST
[root@localhost ~]# 

指定文件名称输出

[root@localhost ~]# script outRename.out
Script started, file is outRename.out
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  outRename.out  soft  typescript
[root@localhost ~]# exit
exit
Script done, file is outRename.out
[root@localhost ~]# cat outRename.out 
Script started on Fri 06 Jul 2018 02:06:19 PM CST
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  outRename.out  soft  typescript
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 02:06:23 PM CST
[root@localhost ~]# 

记录时序

清理一下输出记录文件,然后执行如下命令:

[root@localhost ~]# script -a outRename.out -t 2>timeSeq.out
Script started, file is outRename.out
[root@localhost ~]# pwd
/root
[root@localhost ~]# ./execShell.sh 
pwd:/root
date:Fri Jul 6 14:09:37 CST 2018
[root@localhost ~]# exit
exit
Script done, file is outRename.out
[root@localhost ~]# 
[root@localhost ~]# cat outRename.out 
Script started on Fri 06 Jul 2018 02:09:29 PM CST
[root@localhost ~]# pwd
/root
[root@localhost ~]# ./execShell.sh 
pwd:/root
date:Fri Jul 6 14:09:37 CST 2018
[root@localhost ~]# exit
exit

Script done on Fri 06 Jul 2018 02:09:38 PM CST
[root@localhost ~]# cat timeSeq.out 
0.002387 21
0.107652 8
0.000272 20
0.000036 1
3.347871 1
0.220904 1
0.304105 2
0.497077 7
0.000062 21
0.000129 20
0.000092 1
1.399814 1
0.196987 1
0.198868 1
0.250127 11
0.561254 2
0.975769 11
0.003493 34
0.001882 21
0.000502 20
0.000076 1
0.706303 1
0.204787 1
0.145022 1
0.139094 2
0.123984 6
[root@localhost ~]# 

直接执行命令不使用shell交互

[root@localhost ~]# script -c ls -a c.out -t 2>cSeq.out
Script started, file is c.out
anaconda-ks.cfg  bindcpu  c.out  cSeq.out  execShell.sh  original-ks.cfg  outRename.out  soft  timeSeq.out
Script done, file is c.out
[root@localhost ~]# cat c.out 
Script started on Fri 06 Jul 2018 02:12:58 PM CST
anaconda-ks.cfg  bindcpu  c.out  cSeq.out  execShell.sh  original-ks.cfg  outRename.out  soft  timeSeq.out

Script done on Fri 06 Jul 2018 02:12:58 PM CST
[root@localhost ~]# 

使用静默模式

[root@localhost ~]# script -q  q.out -t 2>qSeq.out
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  q.out  qSeq.out  soft
[root@localhost ~]# exit
exit
[root@localhost ~]# cat q.out 
Script started on Fri 06 Jul 2018 02:16:20 PM CST
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  q.out  qSeq.out  soft
[root@localhost ~]# exit
exit
[root@localhost ~]# 

对比使用静默模式的记录文件,没有记录开始和推出的相关信息

scriptreplay

使用上一步中的文件

[root@localhost ~]# scriptreplay -t qSeq.out -s q.out 
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  q.out  qSeq.out  soft
[root@localhost ~]# exit

[root@localhost ~]# 
[root@localhost ~]# scriptreplay -t qSeq.out -s q.out -d 0.5
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  q.out  qSeq.out  soft
[root@localhost ~]# exit

[root@localhost ~]# scriptreplay -t qSeq.out -s q.out -d 2
[root@localhost ~]# ls
anaconda-ks.cfg  bindcpu  execShell.sh  original-ks.cfg  q.out  qSeq.out  soft
[root@localhost ~]# exit

[root@localhost ~]# 
赞(2) 打赏
转载请注明来源:IT技术资讯 » linux终端录屏与播放:script和scriptreplay

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏