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)