In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to use Shell script to achieve tomcat log regular cutting, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
The significance of log slicing:
In a production environment, when we use tomcat services, if there are too many users, there is no log cutting, there will be a very large log, a day's log can have several G size. It's very troublesome when we need to check the log records. Therefore, log cutting is very necessary!
1. Write shell scripts
Vim fengelog.sh
# script statement #! / bin/bash. / etc/profile. ~ / .bash_profile# definition log file directory applog_path=/usr/local/apache-tomcat-app/logssapplog_path=/usr/local/apache-tomcat-sapp/logs# definition date format d = `date +% Y-%m-%d-%H:% M`d15 = `date-dong15 day ago' +% Ymuri% d` # 15 days date # cutting log cd ${applog_path} & & cp catalina.out $log # log Back up echo > catalina.out # original log clear rm-rf $applog_path/$ {d15} * .log # keep 15-day log cd ${sapplog_path} & & cp catalina.out $sapplog_path/$d.log # log backup echo > catalina.out # original log clear rm-rf $sapplog_path/$ {d15} * .log # keep 15-day log 2. Execute shell script
Chmod + x fengelog.sh
Sh fengelog.sh
3. Add a scheduled task
Crontab-e
0 * / 3 * sh / root/fengelog.sh # set to cut the log every 3 hours
Note:
1. The beginning of the script. / etc/profile,. ~ / .bash_profile is to enable the scheduled task to successfully execute the added environment variables, if not added, the scheduled task will not be executed!
two。 The log retention time and the number of tomcat logs cut at a time, and how long the log is cut, can be customized.
3. It is recommended that after the script is written, run it yourself first to make sure there is no problem, and join the scheduled task!
The above content is how to use Shell script to achieve tomcat log regular cutting, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.