利用 script 和 scriptreplay 记录/回放操作

script makes a typescript of everything displayed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
译文:脚本可以对终端上显示的所有内容进行排版。 对于需要交互式会话的硬拷贝记录作为作业证明的学生来说,它非常有用,因为排版稿文件可以在以后用 lpr(1) 打印出来。

1. script的-t参数

script OPTIONS
-t[file], --timing[=file]
Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time.This information can be used to replay typescripts with realistic typing and output delays.

  1. 根据手册,script -t参数能够:将定时数据输出到标准误差,或在给定时输出到文件。该数据包含两个字段,用空格分隔。第一个字段表示自上次输出以来经过了多少时间。第二个字段表示这次输出了多少个字符。此信息可用于重放具有真实输入和输出延迟的排版脚本。
  2. Emp:
    script -trecord-time.tm shell-script.txt
    这样会生成一个记录时间的文件record-time.sh(记录时间间隔)和一个shell-script.txt(记录输入和输出)的文件,如下:
    • record-time.sh
      在这里插入图片描述
    • shell-script.txt
      在这里插入图片描述

2. scriptreplay

scriptreplay - play back typescripts, using timing information
OPTIONS
-t, --timing file
File containing script’s timing output.
-s, --typescript file
File containing script’s terminal output.

  1. Emp:
    scriptreplay -t record-time.tm -s shell-script.txt
    在这里插入图片描述启动脚本后会自动回放执行的操作并具有当时输入输出时的延迟

3. 对于生成的shell-script脚本

  1. 当使用vim编辑时可能发现他是乱糟糟的,不要在意,那些只是对于字体高亮的一些格式字符,当使用cat将其打印到终端时,会自动解析这些符号
  2. 使用script时完全可以不使用-t参数,这样会得到同样的一个记录文件,同样可以用cat来复现操作
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值