Use shell scripts in linux to cut logs for tomcat and nginx

Source: Internet
Author: User
Tags tomcat

Online servers generally encounter a variety of log cutting. Similar detailed script articles have not been published before. This time, we will make up for the relevant content of the website. The following describes how to cut two logs, and how to cut logs of other services.
Tomcat log catalina. out small cut script:

#! /Bin/bash
# Cut tomcat catalina. out
Yesterday = 'date + "% F"-d "-1 days "'
Cd/usr/local/tomcat7.0.70/log
Cp catalina. out catalina. out. $ yesterday
Echo & gt; catalina. out
Exit

The error message returned when the catalina. out log is too large. The script is only one of the methods, and can be manually configured or implemented using other tools. In addition, if there are many tomcat projects, you can set a variable in the directory for repeated execution in a loop.

Nginx access log cutting script (other logs are similar ):

#! /Bin/bash
# Cut nginx access. log
 
LOGS_PATH =/home/wwwroot/21 yunwei/logs
Yesterday = 'date + "% F"-d "-1 days "'
Mv $ {LOGS_PATH}/21yunwei. log $ {LOGS_PATH}/21yunwei-$ {yesterday}. log
Kill-USR1 $ (cat/var/logs/nginx. pid)

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.