Shell script cuts tomcat log files

Source: Internet
Author: User
Tags log4j

Transferred from: http://www.cnblogs.com/lishun1005/p/6054816.html

In view of debugging Logback and log4j file cutting has not been successful, with the shell to write a script to cut Tomcat under the log file (everyone if you have in Logback or log4j use file cutting success, you can leave the use of the way, first thank you)

1: Nonsense less, directly affixed to the script:

#!/bin/shlog_dir=/var/log/tomcatmonitor_file=$1 absolute path to #tomcat目录下的catalina. out file File_size= ' du-  m $monitor _file | awk ' {print '} ' if [$file _size-ge  ]then        if [!-D $log _dir] then                mkdir/var/log/tomcat   #创建保存切割 File directory, this path can be modified by itself, save to the directory you want        fi        cp $1/var/log/tomcat/log-' date +%y-%m-%d-%h%m%s '. Log   #保存日志文件        echo ' Date +%y-%m-%d-%h:%m:%s ' ": File Cut"  >>/var/log/tomcat/split.log  #记录切割日志        echo "" >    Emptying Tomcat's Log/catalina.out file contents fi

Description: This script is very simple, Linux with a timer does not have a minute to scan the size of the log file, that is, when the file is larger than 100M, first copy the file to the specified directory, and then empty the original Tomcat log files. Here is used crontab to use the timer, as to the syntax of this command here is not much to say, interested in Google, there is still a small shortage, because it is timed to scan every minute log files, so the final cut file size will be in 100~102m between.

Then use the timer to execute the script regularly.

2: Edit the timer code with CRONTAB-E

*/1 * * * * *  sh/lee_js/monitor_script.sh  /opt/apache-tomcat-7.0.67/logs/catalina.out #第一个路径是脚本的路径, The second parameter is the absolute path to the Catalina.out file under Tomcat

and then save

This is the log cut.

Note: If you do not have the crontab command, use Yum to install:

Yum Install Vixie-cronyum Install Crontabs

If the article is inappropriate in terms of presentation and code, you are welcome to criticize. Leave your footprints and welcome the comments! Hope to learn from each other

Shell script cuts tomcat log files

Related Article

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.