TrumanWong

scriptreplay

Replay all actions of a terminal session

Supplementary instructions

scriptreplay is used in the terminal to reproduce all user operations and command output information at that time based on the terminal data file and time log file recorded by the script command. In short, it replays everything that happened in the current terminal session instead of running the command again. For example, when the user enters a command, the typing and deletion of characters will also be reproduced. Ideal for tutorial presentations. Moreover, you can use the script command on machine A to record terminal operations, and you can use the scriptreplay command on machine B to replay them.

grammar

scriptreplay [options] [-t] timingfile [typescript [divisor]]

Options

-t, --timing file # File name for recording time logs
-s, --typescript file # Name of the log file that records terminal data information
-d, --divisor number # means double-speed playback, divide the time intervals recorded in the time log file by number
                           # -d 2 means that the playback speed is twice the speed of the original input of a single command, -d 0.1 means that the playback speed of a single command is slowed down by 10 times
-m, --maxdelay number # Represents the maximum delay time between commands (unit is seconds)
                           # -m 2 means that if the interval between the two commands stored in command.log is greater than two seconds, playback will be performed in two seconds.
-V, --version # Display version information and exit
-h, --help # Display help text and exit

Parameters

  • Time log file: The name of the file that stores time log information
  • Terminal data file: the name of the file that stores terminal data information

Example

# Replay the terminal content. By default, the first parameter is the time log and the second parameter is the terminal data file.
scriptreplay time.file command.log
# Replay the terminal content, the playback fast forward speed is 1, and the maximum delay between commands is 2 seconds
scriptreplay -d 1 -m 2 -t time.file -s command.log

Record terminal content to file

zfb@localhost:~$ script -t 2>time.file -a -f command.log
Script started, file is command.log
zfb@localhost:~$ echo "hello, world"
hello, world
zfb@localhost:~$ echo $(date "+%Y-%m-%d %H:%M:%S")
2020-12-23 20:48:46
zfb@localhost:~$ echo "Bye"
Bye
zfb@localhost:~$ ls -al
total 20
drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48 .
drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49 ..
-rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt
-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt
-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log
-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file
zfb@localhost:~$ exit
Script done, file is command.log
zfb@localhost:~$

Replay terminal content

zfb@localhost:~$ scriptreplay -d 1 -m 2 -t time.file -s command.log
zfb@localhost:~$ echo "hello, world"
hello, world
zfb@localhost:~$ echo $(date "+%Y-%m-%d %H:%M:%S")
2020-12-23 20:48:46
zfb@localhost:~$ echo "Bye"
Bye
zfb@localhost:~$ ls -al
total 20
drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48 .
drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49 ..
-rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt
-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt
-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log
-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file
zfb@localhost:~$ exit

zfb@localhost:~$

Among them, only the command scriptreplay -d 1 -m 2 -t time.file -s command.log is user input, and the others are automatically presented (and the visual effects are consistent with the operations of real users). By looking at the time 2020-12-23 20:48:46 output above, it can be proven that this is replaying the record at that time rather than re-executing the command. In other words, you can move the time.file and command.log files to any machine that supports the scriptreplay command, and you can dynamically reproduce the command input and terminal echo.