How to replay Linux session recorded by the script command

Learn how to replay the Linux session recorded by script command. Visual Linux session recording along with timing information plays past session recording in real-time.

Replay Linux session like video!

In our last article we learned how to record Linux sessions using the script’ command. In this article we will walk through steps to replay recorded sessions by script command. Normally, script command saves recording in the 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 the order you executed them while recording.

If you want to view your recorded output as it is being played on the terminal you can do it using scriptreplay command. It will play your output just as you are typing it on the terminal! scriptreplay needs time logs as well to play recorded sessions. This time logs can be generated using –timing switch with the script command. Let’s walk through 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
kerneltalks
[root@kerneltalks ~]# echo "I love kerneltalks"
I love kerneltalks
[root@kerneltalks ~]# exit
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
0.001666 53
0.009220 1
3.980549 1
0.103633 1
0.191978 1
0.096629 2
0.127128 75
0.000920 1
1.671676 1
0.143421 1
0.080831 1
0.152510 1
----- output trimmed----

It has two columns of data in it. The first column denotes the number of seconds elapsed after the last display action. The second column is the number of characters printed on the screen.

That’s 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 need to feed scriptreplay command to let the show begin! The 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 the GIF file below. See how to actually replay as if the user is typing in the terminal as it was at the time of recording!

‘scriptreplay’ command in action

It replays exactly with the same time difference between two commands as you did at the time of recording! It’s like watching what the user has done in his session in real-time. It’s more of a visual record of Linux session while script was textual records.

One thought on “How to replay Linux session recorded by the script command

  1. Smithk508

    I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a nice day. Bye ageeefekeffdefdf

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.