Script to clean up logs under Linux

Source: Internet
Author: User

Requirement: Because/var partition separately, the size of the partition is 5G, the log is full, you need to write a script to clean up the log files regularly


#!/bin/bash

# #delete Log script, write by XL

Log_dir1=/var/log

Log_dir2=/var/spool/mail

Log_dir3=/var/spool/mqueue

Root_uid=0

# #Must is use as root to run this script

If ["$UID"-ne "$ROOT _uid"]

Then

echo "must is root to run this script."

Exit 1

Fi

CD $LOG _dir1 | | {

echo "Can not change to necessary dircectory." >&2

Exit 1

}

#把空设备重定向到文件里面

Cat/dev/null > Maillog && echo "Logs cleaned up."

Cat/dev/null > Maillog.1 && echo "Logs cleaned up."

Cat/dev/null > Maillog.2 && echo "Logs cleaned up."

CD $LOG _dir2 | | {

echo "Can not change to necessary dircectory." >&2

Exit 1

}

Cat/dev/null > Root && echo "Logs cleaned up."

Cat/dev/null > Stock && echo "Logs cleaned up."

# # #清除mqueue下的小文件

CD $LOG _dir3

LS |xargs RM-RF


This article is from the "Dream Girl" blog, please be sure to keep this source http://dreamgirl1314.blog.51cto.com/1159474/1554726

Script to clean up logs under Linux

Related Article

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.