Linux scriptreplay回放你的高光时刻

简介: Linux scriptreplay回放你的高光时刻

scriptreplay

重新播放终端会话的所有操作

补充说明

scriptreplay 用于在终端中,根据 script 命令记录的终端数据文件和时间日志文件,重现当时用户的所有操作和命令的输出信息。简而言之,重现播放当时终端会话发生的一切信息,而不是重新运行一遍命令。例如,用户当时在输入某条命令时,字符的键入和删除也都会被重现。非常适合用于教程演示场合。而且,在机器 A 上面使用 script 命令记录终端操作,可以在机器 B 上面使用 scriptreplay 命令重新播放。

语法

scriptreplay [options] [-t] timingfile [typescript [divisor]]
选项
-t, --timing file         # 记录时间日志的文件名称
-s, --typescript file     # 记录终端数据信息的日志文件名称
-d, --divisor number      # 表示倍速播放,把时间日志文件记录的时间间隔都除以 number
                          # -d 2 表示播放速度是原始输入单条命令的速度的两倍,-d 0.1 表示播放单条命令的速度减慢 10 倍
-m, --maxdelay number     # 表示命令之间的最大延迟时间(单位是秒)
                          # -m 2 表示 command.log 中存放的两条命令之间的间隔时间如果大于两秒,则按两秒执行播放
-V, --version             # 显示版本信息并退出
-h, --help                # 显示帮助文本并退出

参数

时间日志文件:存储时间日志信息的文件名称

终端数据文件:存储终端数据信息的文件名称

实例

重新播放终端内容,默认第一个参数是时间日志,第二个参数是终端数据文件

scriptreplay time.file command.log

重新播放终端内容,播放快进速度为 1 ,命令之间最大延时为 2 秒

scriptreplay -d 1 -m 2 -t time.file -s command.log

记录终端内容到文件

[root@master1 /tmp]# script -t 2>time.file -a -f command.log
Script started, file is command.log
[root@master1 /tmp]#cd /opt/ser^C
[root@master1 /tmp]#exit
Script done, file is command.log
[root@master1 /tmp]#
[root@master1 /tmp]#
[root@master1 /tmp]#
[root@master1 /tmp]#rm -rf command.log time.file 
[root@master1 /tmp]# script -t 2>time.file -a -f command.log
Script started, file is command.log
[root@master1 /tmp]#cd /opt/ansible/
[root@master1 /opt/ansible]#ll -ths
total 8.0K
   0 drwxr-xr-x  4 root root  75 Jul 16 14:09 chapt7
   0 drwxr-xr-x  3 root root  50 Jul 16 13:29 chapt6
   0 drwxr-xr-x  2 root root 230 Jul 15 17:00 chapt5
4.0K -rw-r--r--  1 root root 876 Jul 15 10:51 ssh-config.yaml
   0 drwxr-xr-x 10 root root 172 Jul 15 08:40 first_role
4.0K -rw-r--r--  1 root root 130 Jul 12 15:45 var.yaml
[root@master1 /opt/ansible]#cat var.yaml 
- hosts: k8s-master
  remote_user: root
  tasks:
    - name: create log file
      file: name=/tmp/{{ ansible_fqdn }} state=touch
[root@master1 /opt/ansible]#kubectl top nodes
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)
[root@master1 /opt/ansible]#kubectl get po -n nexus
^C
[root@master1 /opt/ansible]#ok
bash: ok: command not found
[root@master1 /opt/ansible]#echo bye
bye

重新播放终端内容

[root@master1 /tmp]#scriptreplay -d 2  -t time.file -s command.log
[root@master1 /tmp]#cd /opt/ansible/
[root@master1 /opt/ansible]#ll -ths
total 8.0K
   0 drwxr-xr-x  4 root root  75 Jul 16 14:09 chapt7
   0 drwxr-xr-x  3 root root  50 Jul 16 13:29 chapt6
   0 drwxr-xr-x  2 root root 230 Jul 15 17:00 chapt5
4.0K -rw-r--r--  1 root root 876 Jul 15 10:51 ssh-config.yaml
   0 drwxr-xr-x 10 root root 172 Jul 15 08:40 first_role
4.0K -rw-r--r--  1 root root 130 Jul 12 15:45 var.yaml
[root@master1 /opt/ansible]#cat var.yaml 
- hosts: k8s-master
  remote_user: root
  tasks:
    - name: create log file
      file: name=/tmp/{{ ansible_fqdn }} state=touch
[root@master1 /opt/ansible]#kubectl top nodes
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)
[root@master1 /opt/ansible]#kubectl get po -n nexus
^C
[root@master1 /opt/ansible]#ok
bash: ok: command not found
[root@master1 /opt/ansible]#echo bye
bye

2afa30fa7d4f4571bfebbf6955628815.gif

注意点

其中,只有命令scriptreplay -d 1 -m 2 -t time.file -s command.log是用户输入,其他均为自动呈现(且视觉效果与真实用户的操作一致)。通过查看上面输出的时间2020-12-23 20:48:46,可以证明,这是重新播放当时的记录,而非重新执行一遍命令。也就是说,可以把time.file和command.log文件移动到任意一台支持scriptreplay命令的机器上,都可以动态重现命令输入与终端回显

目录
相关文章
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(三)
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(三)
147 0
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(三)
|
15天前
|
Ubuntu 网络协议 Linux
Linux普通玩家,熟悉这些高频命令
Linux普通玩家,熟悉这些高频命令
8 0
|
9月前
2023年电赛---运动目标控制与自动追踪系统(E题)OpenART mini的代码移植到OpenMV
2023年电赛---运动目标控制与自动追踪系统(E题)OpenART mini的代码移植到OpenMV
114 0
|
5月前
|
传感器 监控 Linux
Linux|奇怪的知识---CPU温度监控
Linux|奇怪的知识---CPU温度监控
104 0
|
12月前
|
存储 Shell 程序员
【Linux】进程信号“疑问?坤叫算信号吗?“(上)
【Linux】进程信号“疑问?坤叫算信号吗?“(上)
53 0
内存清理、动画制作、CPU检测等五款实用软件推荐
人类与99%的动物之间最大差别在于是否会运用工具,借助好的工具,能提升几倍的工作效率。
261 0
内存清理、动画制作、CPU检测等五款实用软件推荐
|
Linux C语言
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(二)
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(二)
172 0
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(二)
|
机器学习/深度学习 Linux Windows
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(一)
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(一)
215 0
操作系统实验五 基于内核栈切换的进程切换(哈工大李治军)(一)