First, we need to explain why we need to record terminal sessions. In this case, there is a cache size limit on the terminal. When messages printed on the terminal are out of the cache range, the printed messages in front of it are automatically lost, which will cause obstacles to our debugging program, so it is necessary to record the complete terminal to print messages! 1. using scripts to record Linux terminal session scripts is part of the util-Linux software package of most linux products. Script records all the content of a session: the content you input and the content you see. It even records the reason why the terminal session is recorded first, because there is a cache size limit on the terminal, when the messages printed on the terminal are out of the cache range, the printed messages in front of it are automatically lost, which will cause obstacles to our debugging program, so it is necessary to record the complete terminal to print messages!
1. Use scripts to record Linux terminal sessions
Script is part of the util-Linux software package of most linux products.
Script records all the content of a session: the content you input and the content you see. It even records the color. Therefore, if your command prompt or program output contains the color, the script records it.
To use a script, run the following command:
$ script
By default, it writes content to the typescript file in the current directory. Then, everything you input is recorded in that file. To record logs in another file, you only need to use the script/path/to/file command.
After the record is completed, enter exit to exit. This command will close the script session and save the file. Now you can use cat or any other program to check log files.
Run in Ubuntu/or other linux,
script screen.log
Start record,
Record screen information to screen. log, record until you exit, record screen log good way...
End record:
Exit
Use instance
- Aulyp @ ubuntu:/home/workspace/Android_eclair_smdk6410 $ sudo script screen. log// Zookeeper has Ç Â ¼
- [Sudo] passwordForAulyp:
- Script started, file is screen. log
- Root @ ubuntu:/home/workspace/android_eclair_smdk6410 # sudo make clean
- ========================================================== ====
- PLATFORM_VERSION_CODENAME = REL
- Platform_versions = 2.1
- TARGET_PRODUCT =Generic
- TARGET_BUILD_VARIANT = eng
- TARGET_SIMULATOR =
- TARGET_BUILD_TYPE = release
- TARGET_ARCH = arm
- HOST_ARCH = x86
- HOST_ OS = linux
- HOST_BUILD_TYPE = release
- BUILD_ID = ERD79
- ========================================================== ====
- Cleaning out/target/product/Generic...
- Cleaning out/target/common...
- Cleaning out/host/linux-x86...
- Cleaning out/host/common...
- Clean.
- Root @ ubuntu:/home/workspace/android_eclair_smdk6410 # exit// Í Ë ö¼ çâ ¼
- Exit
- Script done, file is screen. log
- Aulyp @ ubuntu:/home/workspace/android_eclair_smdk6410 $
The solution has been found, and there is no problem with abnormal exit. The log is still logged. You need to add the parameter script-f ido. log. If mkfifo ido is used on a terminal. log; script-f ido. log on to another terminal and find the ido. log File, and your tail-f will scroll out the content of your operation .. this is very convenient...
2. The disadvantage of using a script is that it records all special characters, so your input file will be filled with control characters and ANSI escape sequences. You can use a very simple shell in the script to solve this problem:
SHELL=/bin/bash PS1=”$ ” script
When using scripts, do not use interactive programs or programs that process windows, such as vior top. They will destroy the output result of the session. In addition, the log file records any command line program you use and the steps you take to complete a task. If you need to edit a file in the script, consider exiting the script session, then use script-a (which adds a new session after the old session) to edit the file, and then restart the session.