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命令的机器上,都可以动态重现命令输入与终端回显

相关实践学习
CentOS 8迁移Anolis OS 8
Anolis OS 8在做出差异性开发同时,在生态上和依赖管理上保持跟CentOS 8.x兼容,本文为您介绍如何通过AOMS迁移工具实现CentOS 8.x到Anolis OS 8的迁移。
目录
相关文章
|
8月前
|
Linux 数据处理
Linux命令scriptreplay的深入解析
`scriptreplay`是Linux工具,用于根据`script`命令记录的终端会话及时间戳重现实时操作。它精确重现用户输入,支持跨机器播放、速度调整,并可用于教学、回顾。通过`-t`指定时间日志,`-s`指定会话日志,`-d`调整播放速度。注意环境差异可能影响重放效果,最好在类似环境下使用。
|
JavaScript Linux 开发工具
Linux文本模式下录制、回放和共享操作记录(script、scriptreplay、mkfifo)的妙用
在生产中,有时候需要把别人的操作过程录制下来,后期可以进行回放查看。还可以实时共享自己的操作,让另一个人在千里之外指导你进行操作。
3155 0
|
1天前
|
Linux
Linux 常用文件查看命令
`cat` 命令用于连接文件并打印到标准输出,适用于快速查看和合并文本文件内容。常用示例包括:`cat file1.txt` 查看单个文件,`cat file1.txt file2.txt` 合并多个文件,`cat > filename` 创建新文件,`cat >> filename` 追加内容。`more` 和 `less` 命令用于分页查看文件,`tail` 命令则用于查看文件末尾内容,支持实时追踪日志更新,如 `tail -f file.log`。
20 5
Linux 常用文件查看命令
|
7天前
|
Linux
Linux od命令
本文详细介绍了Linux中的 `od`命令,包括其基本语法、常用选项和示例。通过这些内容,你可以灵活地使用 `od`命令查看文件内容,提高分析和调试效率。确保理解每一个选项和示例的实现细节,应用到实际工作中时能有效地处理各种文件查看需求。
43 19
|
17天前
|
缓存 Linux
Linux查看内存命令
1. free free命令是最常用的查看内存使用情况的命令。它显示系统的总内存、已使用内存、空闲内存和交换内存的总量。 free -h • -h 选项:以易读的格式(如GB、MB)显示内存大小。 输出示例: total used free shared buff/cache available Mem: 15Gi 4.7Gi 4.1Gi 288Mi 6.6Gi 9.9Gi Swap: 2.0Gi 0B 2.0Gi • to
29 2
|
18天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
107 25
|
1月前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
77 24
Linux系统之whereis命令的基本使用
|
2月前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
56 11
|
3月前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
209 8
|
3月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
312 20