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 record the conversation process by using script command in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces how to use the script command to record the conversation process in linux, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

First, the main function of the script command is the characteristics.

In the Windows operating system, readers may have used some screen recording software, which can record the operation of a certain period of time in the form of video. But in the Unix operating system, sometimes you don't have to be so troublesome. Because the operating system provides a script command to help the system engineer record the process of a session. This is a rather obscure command and is not in the POSIX specification. For this reason, some Unix operating system versions may not have this feature. Many systems engineers may have little contact with this command. However, the author likes this order more. To put it simply, the system engineer can use this command to record the entire process of a session or some of the operations in the middle into a file. Using this command, you can basically record most of the keyboard operations, the output of the command, and error messages in the file. In other words, basically all the information output on the screen can be saved in this file. The system administrator can then review the file afterwards to get the necessary information. So how do you use this command? As shown in the picture below, it is actually very simple.

This is the basic process used by the script command. First, when the systems engineer wants to record a session, he only needs to enter the script command at the beginning of the session. After entering this command, the system will save all keyboard operations, screen output, error messages, etc., of the current user to a specific file. For example, after executing the ps command and the who command above, you hope to save these two commands (the user's keyboard operation), the screen output (the result of the execution of the command), and so on to the file. When the engineer needs to exit the recording process, simply enter the exit command, and the system will be the prompt for script done. Indicates that the system has finished recording.

When the system engineer needs to view the information about this file, he can use the cat or vi command to view the contents of the file. However, the version of shell used is different, and their first results may be different. For example, in some versions, using the cat command to view the file may only show when the command is completed, not the user's keyboard operation and screen output. For this reason, the author establishes the use of vi command. Use the vi command to view this file, and there will be no differences between versions. If you use the vi typescript command, you can view the specific information in this file. Typically, the entire file contains the following sections.

The * lines are comment information. For example, "Script started on 18:24:21 on Monday, June 15, 2009". This prompt shows the time when the command began to execute. Then in the * line, there is a similar prompt. However, the prompt on the * * line shows the time when the command was completed, showing the completion date and specific time of the command execution. Then the middle part is the information about the command and the output. If there is an error message during the execution of the command, it will also be recorded here.

Second, matters needing attention in the use of the scirpt command.

As you can see from the screenshot above, this command is not very complicated to use. However, there are some details that system administrators still need to pay attention to. Specifically, there are the following aspects to pay attention to.

* you need to pay attention to the problem of duplicate records. The system engineer may only need to record part of the operation, so this command may be turned on and off frequently during the century's work. It is important to note, however, that the original file is overwritten by default when you use the script command. For example, now the system engineer first uses the script command to record the ps operation, and the system will generate a file called typescript, record the information about the command operation, and then abort the command. Use this command again after a while to record the who operation. At this point, the system will produce an identical typescript file. At this point, the system will overwrite the previous record file. Obviously, this may run counter to the original intention of the systems engineer. The system engineer wants the subsequent actions to be saved in the original record file rather than overwritten. If this requirement is to be implemented, the system engineer must use an optional parameter when executing this command. Start the command in the form of script-a. At this time, the system will not overwrite the original record content, but will append the subsequent operation content to the original file.

The second is that all operations are not recorded. For example, the system engineer starts the script command first. If the operation information of the password is also recorded in the record file, it will obviously bring some security risks. But this worry is superfluous. Readers can go back to test, normally this password information will not be recorded in this file. For this reason, the content that is not output on the screen will not be saved to this record file. Therefore, the author says that this concern of users is unnecessary.

The third is that certain commands are not recorded. The author mentioned above that some keyboard operation records will not be saved. That is, as long as there is no output information on the screen, it will not be saved to the record file. But this is a sufficient and unnecessary condition. That is, the reverse is not true. Not everything displayed on the screen will be recorded in this file. For example, some operation commands in full-screen mode, such as vi commands, will not be recorded in this file. For this reason, systems engineers need to foresee this when using this tool. During the operation, if you need to record the relevant session process, you need to avoid using some full-screen commands as much as possible. For example, when setting environment variables, try not to use vi directly to modify the relevant configuration files. Instead, use non-full-screen commands such as set to manipulate environment variables. In this way, the operating system can record the completed operation process.

The fourth systems engineer needs to understand how some special keys are represented in the file. As the author has done above, the record file basically records all keystrokes. For example, now the user enters the ls-1 command to view the details of all the files in the current directory. Later, the user backed out and used the backspace key to remove the following-l parameter. At this point, the operation of the backspace key will also be saved to the record file. But these specific function keys are represented by some special symbols in the file. For example, the backspace key uses the "[K" character symbol in the file. So moving keys to the cursor or del delete keys and so on are represented in different ways. Only after you are familiar with the meaning of these codes can you really read this file. However, although the form of its representative is different, there are still some rules to follow. That is to say, special function keys begin with [. If the system engineer sees this character, he needs to consider whether it represents a particular function key.

Fifth, you can determine the file name of the record and the path to save according to your own needs. If the system engineer uses the script command directly, the system will automatically name the file. And this file is saved by default in the directory where the command is executed, that is, the current directory. The system engineer can also customize the name and save path of the record file when executing the command. If you can use this command script log, let the system save the relevant records in the log file under the current folder. If the file does not exist, the system automatically creates the file. If it exists, the original file will be overwritten unless the-an argument is used in the command. The system engineer is not alerted before overwriting. Therefore, this point should be paid attention to by system engineers to prevent files from being accidentally deleted.

Sixth, it is important to note that if there is picture information in the output, it cannot be read properly in this file. For example, during session recording, a graphics window is launched using the netconfig command. The information in this graphics window is not reflected correctly in the record file. When the systems engineer looks at the record file, all he may see is a series of [k symbols. * it is important to note that the script command is only valid for the current session. That is, even if the script command is started under the root account, the system still records the actions of the current session. There will be no impact on the sessions of other users, and the actions of other users will not be recorded.

Thank you for reading this article carefully. I hope the article "how to record the conversation process by using script commands in linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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