Linux splits tomcat logs through crontab __linux

Source: Internet
Author: User
Linux splits tomcat logs through crontab

Tomcat Catalina Log decisive time will be very large, can not be viewed, there are many kinds of log segmentation methods on the Web. This paper mainly studies the process of segmenting tomcat logs via Linux crontab timing tasks: First Prepare sh execution script

The following script is to split the Catalina.out log under Log_path, move the log to the Log_path/cron directory and rename it to Catalina.out. Current date. Log

#!/bin/sh
#需要进行分割log的路径, this script generally only modifies this path to use
log_path=/home/webapp/apache-tomcat-7.0.61/logs
#获取当前日期
d= ' Date +%y-%m-%d '
#获取30天前的日期
d90= ' date-d ' day ago ' +%y-%m-%d '
#cd到log_path路径下 and copy log files to the cron directory
CD ${log_path} && cp catalina.out $log _path/cron/catalina.out. $d. Log
#清空原日志文件
echo > Catalina.out
#移除30天前的日志文件
crontab timed Task

Save the script file as an. sh suffix file and place it on the Linux server. Can be the first SH run to see whether the error, if the report file cannot find such errors, first check the path is correct, if the path is not a problem, you need to check the SH file format, the following steps to check and set script file format. VI Command Open SH script run set FF see if the file format is UNIX if the file format is not UNIX, run set Ff=unix:wq save and exit

Re-run the sh script file without problems, configure the Crontab timed task, timed direct script files. CRONTAB-E open crontab Edit; Edit crontab execute split script every night 11:55
* * * * SH script directory/**.sh:wq save and exit. Crontab scheduled Task configuration completed. You can check whether the setting is successful by crontab-l

OK, so you can see whether the log is automatically cut and finished the next day.

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.