Tuesday, 20 September 2016

Record & replay Linux terminal sessions using script/scriptreplay & convert them to GIFs using congif.

The script command is available by default on most *nix distributions & is a neat tool for capturing the output of our terminal session to a file. To run the script command type

#script <file name>

If no file name is specified then the output is saved to a file called typescript in the directory from where script command was run.

We can also append session output to the script command by typing

#script -a <file name>

Script combined with scriptreplay command provides an easy to use yet powerful functionality to replay a terminal session recorded with script command.

The catch is that we need to capture the timing information in a time file. The time file contains two pieces of information. The time elapsed since characters were last displayed on the screen & the number of characters typed on the display now.

The timing information is redirected to standard error. So to start the script session while capturing timing information type:

script -t 2> time.txt cmd.txt

To use scriptreplay to replay the session type:

scriptreplay time.txt cmd.txt

Here's a live demo:



Using congif to convert a script session recording into a GIF.

Congif is a tool tool to convert script session recordings to GIF files. You can download congif from github. Once downloaded extract the source code & run make to install the congif binary. 
To create a GIF using congif type:

./congif -l 0 /root/time.txt /root/cmd.txt

  • -l 0 means to replay the GIF in an infinite loop.
  • time.txt is the timing information file
  • cmd.txt is the script command output file.
The output of this command will be a GIF file called con.gif created in the current working directory.

Here's a quick demo:


No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...