Use Ubuntu-record the logs output by the terminal

Source: Internet
Author: User
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

  1. Aulyp @ ubuntu:/home/workspace/Android_eclair_smdk6410 $ sudo script screen. log// Zookeeper has Ç Â ¼
  2. [Sudo] passwordForAulyp:
  3. Script started, file is screen. log
  4. Root @ ubuntu:/home/workspace/android_eclair_smdk6410 # sudo make clean
  5. ========================================================== ====
  6. PLATFORM_VERSION_CODENAME = REL
  7. Platform_versions = 2.1
  8. TARGET_PRODUCT =Generic
  9. TARGET_BUILD_VARIANT = eng
  10. TARGET_SIMULATOR =
  11. TARGET_BUILD_TYPE = release
  12. TARGET_ARCH = arm
  13. HOST_ARCH = x86
  14. HOST_ OS = linux
  15. HOST_BUILD_TYPE = release
  16. BUILD_ID = ERD79
  17. ========================================================== ====
  18. Cleaning out/target/product/Generic...
  19. Cleaning out/target/common...
  20. Cleaning out/host/linux-x86...
  21. Cleaning out/host/common...
  22. Clean.
  23. Root @ ubuntu:/home/workspace/android_eclair_smdk6410 # exit// Í Ë ö¼ çâ ¼
  24. Exit
  25. Script done, file is screen. log
  26. 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.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.