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 shell to automatically compress logs and clean up compressed packages

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

Share

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

This article will explain in detail how to use shell to automatically compress the log and clean up the compressed package, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Use the find command to find out the relevant files that meet the criteria in the folder.-mtime + 1 and + 15 are the conditions for the filtering time. Calculated on a 24-hour basis, it is not a natural day, that is, 18:00, which can delete files outside the past 24 hours.

-exec command parameter {} where curly braces refer to the value from the previous find, and exec and the following command refer to the command argument to the value from find

Enter the relevant execution conditions in crontab.

#! / bin/sh

# find out the 48-hour log under / app/lv/xinghuo-qiantai10.caiwu.corp and compress it

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 1-name "itmweb.log_2017-*.log"-exec gzip {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 1-name "host-manager*.log"-exec gzip {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 1-name "catalina.*.log"-exec gzip {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 1-name "localhost*.log"-exec gzip {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 1-name "manager*.log"-exec gzip {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/backup-mtime + 1-name "rpcinfo.2017*.log"-exec gzip {}\

# find the logs under / app/lv/xinghuo-qiantai10.caiwu.corp for more than 15 days and delete them

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 15-name "itmweb.log_2017-*.gz"-exec rm-rf {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 15-name "host-manager*.gz"-exec rm-rf {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 15-name "catalina.*.gz"-exec rm-rf {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 15-name "localhost*.gz"-exec rm-rf {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/-mtime + 15-name "manager*.gz"-exec rm-rf {}\

Find / app/lv/xinghuo-qiantai10.caiwu.corp/backup-mtime + 1-name "rpcinfo.2017*.gz"-exec rm-rf {}\

On how to use shell to achieve automatic compression of logs and clean up compressed packages to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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