Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Asciinema for Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Linux uses Asciinema. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Asciinema is an open source and free terminal recording tool, which can save any content of command line input and output plus time in a file, and also provides a way to play it back in a terminal or web browser.

Asciinema recording and playback are text-based, compared with the traditional video has many advantages, such as the small size of the recorded file, you can pause to copy the text content during playback, and so on. At the same time, asciinema also provides a website where you can upload the recorded content to asciinema.org for display if you like, and you can also find many interesting terminal videos here. Asciinema consists of the following three subprojects:

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Asciinema: terminal session Recorder based on Command Line

Asciinema.org: a website that provides API for uploading videos and displays

Javascript player: a js player used to play videos on web

Asciinema is very easy to install and use. Let's take a look at it.

Installation

Asciinema is developed for python and can be installed directly through apt-get, yum or pip

# apt-get install asciinema

View the version after installation is complete

# asciinema-- version asciinema 2.0.2

There are v1 and v2 versions of asciinema, which are quite different. Coffee King uses v2, and all of the following are based on v2 demos.

Asciinema has five parameters, which are recording: rec, playback: play, viewing recording as file: cat, uploading files to asciinema.org website: upload, asciinema.org account authentication: auth. This document mainly describes the use of rec and play.

Recording

# asciinema rec ops-coffee.cast

There are several parameters you can use:

-- stdin means to enable standard input recording, which means that normally, the information of linux input password will not be displayed. If this option is enabled, you can record the password output from the keyboard. However, this feature does not seem to be officially supported, and you will not see the effect after adding it.

-- append adds recording to an existing file.

-- raw saves the original STDOUT output without timing information.

-- overwrite if the file already exists, overwrite it.

-c the command to be recorded, defaults to $SHELL.

-e list of environment variables to capture, default to SHELL,TERM.

-t is followed by a number to specify the title of the video.

-I is followed by a number to set the maximum idle time recorded during recording.

-y enter yes for all prompts

-Q silent mode. When this parameter is added, there is no prompt when you enter or exit recording.

Enter exit or press ctrl+D at the same time to exit recording.

Play

# asciinema play ops-coffee.cast

There are two parameters you can use:

-s is followed by a number, indicating that the video is played at several times the speed.

-I is followed by a number to indicate the maximum number of seconds of free time when playing the video.

In the process of playback, you can use the space to control the pause or playback, you can also use the ctrl+c key combination to exit the playback, when you press the spacebar to pause, you can pass. To display what is to be played frame by frame.

File

The file suffix recommended by asciinema is .cast. Of course, linux does not care about the file suffix. You can use whatever you want. It is recommended to use .cast according to the specification. The contents of the file are as follows.

# cat ops-coffee.cast {"version": 2, "width": 237,55, "timestamp": 1572646909, "env": {"SHELL": "/ bin/bash", "TERM": "linux"}, "title": "ops-coffee"} [0.010014, "o", "root@onlinegame:~#"] [1.296458, "o", "exit"] [1.976439, "o" "\ r\ n"] [1.976532, "o", "exit\ r\ n"]

The cast file mainly consists of two parts, a dictionary on the first line, which is called header

{"version": 2, "width": 237,55 "height", "timestamp": 1572646909, "env": {"SHELL": "/ bin/bash", "TERM": "linux"}, "title": "ops-coffee"}

Header is very simple. The fields mean: version version, width and height represent the width and height of the recording window, the timestamp of the start of timestamp recording, the-e parameter setting specified by env recording, and the-t parameter setting specified by title recording.

The next thing is fixed format content, which is actually IO stream information.

[0.010014, "o", "root@onlinegame:~#"]

Each row is a list of three parts.

The first part is a floating-point number that represents the time it takes to input and output this line of content.

The second part seems to be a fixed string and no instructions are found for what it is used for.

The third part is the specific input and output content.

The design of this file format is still very elegant. At the beginning, header declares that if the video is terminated due to any accident, the entire video will not be lost, and the video can be added by append, which is very useful when you need to pause recording for a long time. More importantly, it can be read by stream, taking up little memory, and there is no need to put the entire video file in memory. It is more friendly to record and play for a long time.

Automatically record audit log

If you have experienced a rigorous IT audit, or useful to the fortress machine, you will know that the operation process needs to be recorded and added to the audit, and if you have the experience of not knowing who operated and what caused the data to be deleted, you will know how important the record of the operation process is, and then use a simple case study to introduce the practical value of asciinema.

It is very simple, just add the. bash_profile file to the devuser user's home directory, as follows:

$cat ~ / .bash_profile export LC_ALL=en_US.UTF-8 / usr/local/bin/asciinema rec / tmp/$USER-$ (date +% Y%m%d%H%M%S) .log-Q

The reason for adding export LC_ALL=en_US.UTF-8 is that it is possible for the system to report an error:

Asciinema needs a UTF-8 native locale to run. Check the output of locale command.

The-Q parameter is added to the rec command when recording, so that there is no prompt about asciinema when entering or exiting, so it is easy to use.

In this way, devuser users will automatically open a video every time they log in, and if you need to audit or check the operation, you only need to play back the video.

You might say that history commands can also record user actions, what are the advantages of asciinema? asciinema can not only record user input, but also record the output of the system, that is to say, history can only record commands executed, while asciinema can also record the results of execution.

Thank you for reading! This is the end of this article on "how Linux uses Asciinema". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report