Linux Log timed Cleanup script

Source: Internet
Author: User

The service log fills the server disk frequently, and if you do not clean it, the service may not work correctly. Appropriately increase the print level of the log, such as the info level to warn can be temporarily mitigated, but not long,

You have to write a script to clean it up regularly.

#!/bin/bash#clearlog.shnginxdir=/usr/local/nginx/logs/*devinfo= ($ (df-l | awk ' {print $} '))     #日志所处的磁盘perInfo = ($ (df-l | awk ' {print int ($)} ')) #磁盘使用率for i in ' seq 0 ${#perInfo [@]} ';d o    if [[${devinfo[i]} = '/dev/xvda1 '] && [[${perinfo[i]}-ge 80]];< C2/>then for           file in $nginxDir;     Do         exist= ' echo $file | awk ' {if (match ($0,/\.log/)) print "Yes"} ";         if [[-F $file]] && [[${exist} = yes]];         Then           echo ' > $file;           echo $ (date) $file "Clear log ok!" >>/var/log/clear.log;         fi;     Done   fi;    Done

Determine the use of the log disk, the general usage rate of 80% can be cleaned up.

Then start a timed task:

Crontab-e

Input:

0/30 * * * */xxx/clearlog.sh

Detect disk usage every 30 minutes



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Log timed Cleanup script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.