Learn how to replay Linux session recorded by script command. Visual Linux session recording along with timing information plays past session recording in real time.
In our last article we learned how to record Linux session using ‘script’ command. In this article we will walk through steps to replay recorded session by script command. Normally, script command saves recording in plain text log file which can be viewed using cat, more, less or vi commands. That would be only plain text having commands and their outputs in order you executed them while recording.
If you want to view your recorded output as it is being played on terminal you can do it using scriptreplay command. It will play your output just as you are typing it on terminal! scriptreplay needs a time logs as well to play recorded session. This time logs can be generated using –timing switch with script command. Lets walk though these steps.
How to record Linux session with timing
We will use script command with –timing switch followed by filename in which all timing logs will be saved.
[root@kerneltalks ~]# script --timing=time.log capture.txt
Script started, file is capture.txt
[root@kerneltalks ~]# date
Thu Jul 27 02:42:46 EDT 2017
[root@kerneltalks ~]# hostname
[root@kerneltalks ~]# echo "I love kerneltalks"
I love kerneltalks
[root@kerneltalks ~]# exit
Script done, file is capture.txt
here we are saving timing information in time.log file and session recording in capture.txt file. Both are plain text files and can be viewed. If you look at time.log file :
[root@kerneltalks ~]# cat time.log
----- output trimmed----
It has two columns data in it. First column denotes number of seconds elapsed after last display action. Second column is number of characters printed on screen.
Thats it. You have recorded your Linux session along with timing logs. This recording (capture.txt) can be replayed using scriptreplay command since its timing information is available.
How to replay recorded Linux session
Now both logs timing and recording needs to feed scriptreplay command to let show begin! Format and switch would be the same. Command used to replay session will be :
# scriptreplay --timing=time.log capture.txt
To see it in action, I captured it in GIF file below. See how to actually replay as if user is typing in terminal as it was at the time of recording!
It replays exactly with same time difference between two commands as you did at the time of recording! Its like watching what user has done in his session in real time. Its more of a visual records of Linux session while script was textual records.