[Switch] terminal logging tool script for Linux notes

When learning Linux, sometimes the printing messages of the terminal are very important to us, but the terminal display also has a certain buffer space. When there is a lot of printing information, the previous information will be overwritten, so here I searched for this aspect on the Internet. The introduction is summarized as follows:    

script is a very useful tool, but also fun enough. script can record the session process of the terminal, and then use scriptreplay to play the recorded result for others to watch. The advantage of script is that all your operations in the terminal can be recorded natively. We can use this kind of recording in many ways, such as teaching, demonstration, and so on.


    In general, script and scriptreplay are installed by default in Linux distributions. If you plan to start recording a terminal session using script, you can type the following command: 

script -t 2>yangrui.timing -a yangrui.session

    The -t option in this command specifies to output the recorded time data, and the -a option outputs the recorded file (if the file already exists, the data is appended). You can replace yangrui in the command with the file name you set. When the message "Script started, file is yangrui.session" is returned in the terminal, you can perform the operations that need to be recorded.

If you need to end the recording process, enter

 

exit

 

To play a recorded terminal session, use the command:

 

scriptreplay yangrui.timing yangrui.session

You can view the operation like watching a movie, but you can't fast-forward and rewind (it's also possible that I haven't found it yet, if anyone knows, you can teach me by the way laughing out loud). Personally recommend to use:

cat yangrui.session

 

View content. If you open yangrui.session in the graphical interface, you will find that the file will be full of control characters and ANSI escape sequences, which looks like garbled characters:

 

 

The solution can be found on the Internet. Personally, it is recommended to use the command line to view it.

 

The next time you want to continue recording, just type again:

 

script -t 2>yangrui.timing -a yangrui.session

It will put the recorded data after the last data, and automatically separated by time. For more information on script and scriptreplay, use man script or man scriptreplay query.

 

Reprinted from: http://www.voidcn.com/article/p-rmsdfepb-xr.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326077077&siteId=291194637