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

What is the solution to oversized log files under Linux?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article shows you what is the solution to the excessive log file under Linux, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

I do not know if you have encountered, the system suddenly appeared a problem, the system frantically hit the log, resulting in disk problems, or too many logs simply can not read.

It often occurs to you that you can split the log files so that you can leave important logs and delete unnecessary logs. This method is described in detail below.

We can split the log every day, so in this way, in order to avoid confusion, the log we split should be dated. Of course, the date can be obtained by the following statement:

> current_date= `date-d "- 1 day"+% Y%m%d" `

Date-d "- 1 day" means to get the date of the previous day, which means that if we operate today, we will cut yesterday's log. +% Y%m%d is the specific date format, that is, the year, month and day format, for example: 20181005.

Next, let's cut the log.

> split-b 65535000-d-a 4 myout.txt. / log/log_$ {current_date} _

Among them, 65535000 is 60m, that is, log files are cut according to 60m size, which can be customized. -d-a 4 indicates that the file suffix is 4 digits. After we cut the documents, we have to number them in order, such as 0000Thelm 0001jcm0002. This 4 represents the number of digits.

After that,. / log/log$ {current_date} is the prefix of the sliced log file, which contains the current date. So, the final output format is similar to: log_20181005_0001.

After the log file is cut, you can delete the log file, otherwise it will lose the meaning of cutting the file. Deletion can be done in the following ways:

> cat / dev/null > nohup.out

Write the above commands in a script and run it every day, you can cut the log file into several pieces for us to check. The complete code is as follows:

> #! / bin/bash current_date= `date-d "- 1 day" +% Y%m%d "`date-b 65535000-d-a 4 / home/alvin/myout.txt / home/alvin/log/log_$ {current_date} _ cat / dev/null > nohup.out what is the solution that the log file under Linux is too large? have you learned any 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.

Share To

Internet Technology

Wechat

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

12
Report