Linux screen print log

Source: Internet
Author: User

Requirements: A company background program is executed under screen, only by restoring to the window to view and unable to view all the information, because the background program needs to restart the background, by looking at the background program execution process to determine whether the update is successful, Now it is necessary to print the screen run information of the background program to the log and provide debugging to the developer.

Implementation ideas: 1. Output the screen log to a file and give the developer access to read the file;

2. Add the log name to the time, so that the log name can easily identify whether the background restart success;

3. Delete the original log every time you restart the background to save space and regenerate log names with time

Implementation process:

Important: 1. Change the screen profile/ETC/SCREENRC add a line at the end Logfile/root/screenlog/%t-20140905-163549.log

2. The start screen command needs to be accompanied by relevant parameters

/usr/bin/screen- L - t aa1-dms Aa1./aa1

Here I implement a script, the log file name will be generated based on time.

#!/bin/bashexport LANG=ZH_CN. Utf-8declare-i portkillall Screenrm-rf/root/screenlog/*.logecho "logfile/root/screenlog/%t-' Date +%Y%m%d-%H%M%S '. Log ">>/opt/sjzq/screenrc_temp\cp-rf/opt/sjzq/screenrc_temp/etc/screenrcfor i in ' seq 1 6 ' Do        n= ' pgrep aa$i | Wc-l '        if [$n-eq 0];then                cd/fb$i                /usr/bin/screen-l-t Aa$i-dms aa$i./aa$i >/dev/null 2&1        FID Onesed-i ' $d '/opt/sjzq/screenrc_temp


Each time the guard1.sh is executed, the screen is restarted, and we see that the log is generated under/root/screenlog with a combination of Session name + time, so that we can determine the log restarts and be able to view the relevant logs.
[Email protected] sjzq]# bash guard1.sh [[email protected] sjzq]# Ls/root/screenlog/aa1-20140905-165056.log  Aa2-20140905-165056.log  aa3-20140905-165056.log  aa4-20140905-165056.log  aa5-20140905-165056.log  aa6-20140905-165056.log[[email protected] sjzq]# bash Guard1.sh[[email protected] sjzq]# ls/root/screenlog/ Aa1-20140905-165127.log  aa2-20140905-165127.log  aa3-20140905-165127.log  aa4-20140905-165127.log  Aa5-20140905-165127.log  Aa6-20140905-165127.log


Linux screen print log

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.