Linux Log Session Commands

Source: Internet
Author: User
Tags versions

In UNIX system maintenance, system engineers sometimes want to be able to record the process of a session. When testing a system function, the engineer would like to record the steps of the test. To use this data for follow-up analysis in the case of problems. If you are making a training document sometimes, you may also need these session records to facilitate the trainer to make PPT and other training documents. In a word, System engineers now want to record the process of a session, in the UNIX system can be implemented?

First, the script command's main function is in the characteristic.

In the Windows operating system, readers may have used some screen recording software to record the operation of a certain period of time in the form of video. But in Unix operating systems, there are times when you don't need to be so troublesome. Because the operating system provides a script command to help system engineers to record the process of a session. This is a less-than-rare command and is not in the POSIX specification. For this reason, some UNIX operating system versions may not have this feature. Many system engineers may rarely contact this command at ordinary times. But the author is more like this order. Simply put, a system engineer can use this command to log the entire process of a session or some action in the middle to a file. With this command, you can basically record most of the keyboard actions, the output of the command, and the error message in the file. That is, the information that is printed on the screen can basically be saved in this file. The system administrator can then view the file after the event to obtain the necessary information. So how does this command work? The following figure, in fact, is very simple.

As shown in the figure above, this is the basic procedure used by the script command. First, when a system engineer wants to record a session, you only need to enter the script command at the beginning of the session. When you enter this command, all keyboard actions, screen output, and error messages for the current user are saved to a specific file. When the PS command and the WHO command are executed above, you will want to save the two commands (user's keyboard action), screen output (the results of the command execution), and so on to the file. When an engineer needs to exit the recording process, only the exit command is required, and the system will be the script-done message. Indicates that the system has finished recording work.

When a system engineer needs to view the information for this file, you can use the cat or VI command to view the contents of the file. However, unlike the shell versions used, they may have a different result first. If you use the Cat command to view this file in some versions, you may only show when the command is complete, not the user's keyboard action and the on-screen output information. To this end the author established the use of VI command. Using the VI command to view this file, there will be no difference between the version of the problem. 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 first line is the annotation information. such as "Script started on June 15, 2009 Monday 18:24 21 Seconds". This message displays the time that the command started executing. Then, in the last line, there is a similar hint. However, the last line of the message shows the completion of this command time, showing the completion of the command execution date, the specific time, such as the West virtual. Then the middle part is the information about the command and output results. If there is an error message during the execution of the command, it will be recorded here as well.

Second, the SCIRPT command to use the attention items.

From the screenshot above you can see that this command is not very complicated to use. However, the system administrator still needs to be aware of some details. Specifically, there are several aspects to be noted.

The first need to pay attention to the issue of duplicate records. The system engineer may only need to record part of the operation, for which this command may be opened and closed frequently during the century work. However, it should be noted that the original file is overwritten by default when the script command is used. If the system engineer first uses the script command to record the PS operation, the system will produce a file called Typescript, which records the information about the command operation, and then terminates the command. After a while, the command is reused to record the WHO operation process. At this point the system will produce an identical typescript file. At this point the system overwrites the original record file. Obviously this may be contrary to the original intention of the system engineer. The system engineer hopes that subsequent operations will be saved in the original record file, not overwritten. If this requirement is to be implemented, then the system engineer must use an optional parameter when executing the command. That is, to start the command in the form of script–a. At this point, the system will not overwrite the original record content, but the subsequent operation of the content appended to the original file.

The second is not to record all operations. If the system engineer starts the script command first. And then using the passwd command to modify the password for the current account or other accounts (logged in as a privileged user), will the password information also be recorded? If the operation information of the password is also recorded in the record file, it will obviously bring some security hidden trouble. But this worry is superfluous. Readers can go back and test that the password information is normally not recorded in this file. In fact, you can imagine, after entering the passwd command, enter a new password, the screen will not display the user's input, that is, the new password. For this reason, the content that has no output on the screen is not saved to this record file. So the author said that the user's concern is not necessary.

The third is that certain commands are not logged. I mentioned above that some keyboard operation records are not saved. That is, any information that is not printed on the screen will normally not be saved to the record file. But this is a sufficient and unnecessary condition. That's not true in turn. Not all of the displayed content on the screen will be logged into this file in 1510. Like some full-screen mode of operation commands, such as VI command, etc., will not be recorded in this file. This is a situation that the system engineer needs to anticipate when using this tool. If you need to record the relevant session process while you are working, you need to avoid using some full-screen commands as much as possible. If you are setting up an environment variable, try not to use VI to modify the related profile directly. Instead, you use a non-full-screen command such as set to manipulate the environment variables. This allows the operating system to record the completed operation.

The system engineer needs to know how some special keys are represented in the file. The above author, the record file will basically record all the keyboard percussion action. If the user enters the ls-1 command now, first view the details of all the files in the current directory. Later, the user reneged on the use of the BACKSPACE key to the back of the-l parameter removed. The operation of the backspace bar will also be saved to the record file. However, these specific function keys are represented by special symbols in the file. such as the backspace bar in the file is a "[K" character symbol. So the move key to this cursor or del delete keys and so on have different ways of representing. Only when you are familiar with the meaning of the code can you really read this file. But the form of representation is different, but there are some rules to follow. That is, the general special function keys are to [start with]. If the system engineer sees this character, then you need to consider whether it represents a particular function key.

The other is that the file name and the saved path can be determined 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 executes, 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 keep the related records in the log file under the current folder. If this file does not exist, the system will automatically create this file. If it exists, the original file will be overwritten unless the-a parameter is used in the command. The system engineer is not reminded before overwriting. So this system engineer should pay attention to prevent the file from being accidentally deleted.

The sixth is to note that if there is picture information in the output, it will not be read correctly in this file. As part of the session recording process, a graphics window was started using the Netconfig command. The information in this graphics window is not reflected correctly in the log file. When a system engineer looks at a record file, it may only see a series of [k symbols]. The last thing to note is 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 operation of the current session. The other user's session will not have the slightest effect, nor will the other user's actions be logged.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.