In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
How to use Shell script to achieve tomcat log cutting? I believe that most people have not yet learned this skill, in order to let you learn, to give you a summary of the following content, do not say much, let's move on.
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:
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!
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!
After reading this article, have you learned how to use Shell scripts to cut tomcat logs? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.