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

目录
相关文章
|
Linux 数据处理
Linux命令scriptreplay的深入解析
`scriptreplay`是Linux工具,用于根据`script`命令记录的终端会话及时间戳重现实时操作。它精确重现用户输入,支持跨机器播放、速度调整,并可用于教学、回顾。通过`-t`指定时间日志,`-s`指定会话日志,`-d`调整播放速度。注意环境差异可能影响重放效果,最好在类似环境下使用。
|
JavaScript Linux 开发工具
Linux文本模式下录制、回放和共享操作记录(script、scriptreplay、mkfifo)的妙用
在生产中,有时候需要把别人的操作过程录制下来,后期可以进行回放查看。还可以实时共享自己的操作,让另一个人在千里之外指导你进行操作。
3242 0
|
1月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
282 1
二、Linux文本处理与文件操作核心命令
|
1月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
548 56
|
15天前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
143 2
|
25天前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
75 0
Linux内存问题排查命令详解
|
1月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
138 16
|
1月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
|
3月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
704 13
|
4月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
676 21

热门文章

最新文章