Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use scheduled tasks to delete Tomcat log information in CentOS7

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use scheduled tasks to delete Tomcat log information in CentOS7, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

1. Create a shell script at the specified location

Vi / usr/sbin/clear_tomcat_logs.sh

two。 Write script content

#! / bin/bash# cleans up the log information of tomcat8080 30 days ago ("clear_tomcat_8080" is the variable name) clear_tomcat_8080=/data/tomcat-8080/logs/test/testproject.log.$ (date-d "`date'+% F``30 days ago"+% F") _ * rm-f $clear_tomcat_8080# cleans up the log information of tomcat8081 30 days ago ("clear_tomcat_8081" is the variable name) clear_tomcat_8081=/data/ Tomcat-8081/logs/test/testproject.log.$ (date-d "`date'+% F'`30 days ago"+% F") _ * rm-f $clear_tomcat_8081

3. Permissions to view files

Ll clear_tomcat_logs.sh

If it is not for this permission, the file may not be executed, just execute the following command

Chmod 755 clear_tomcat_logs.sh

4. Add scheduled tasks, open / etc/crontab file

Vi / etc/crontab

5. Add scheduled task information

# use root users to execute clear_tomcat_logs.sh file 1503 * root / usr/sbin/clear_tomcat_logs.sh in the / usr/sbin/ directory at 03:15 every morning

6. Load scheduled task information to make it effective

Crontab / etc/crontab

7. View scheduled task information

Crontab-l

8. Extension: view a list of scheduled tasks for specified users

The user name specified by crontab-u-l after reading the above, do you have any further understanding of how to use scheduled tasks to delete Tomcat log information in CentOS7? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report