Scheduled cleanup of disk log steps under Linux

Source: Internet
Author: User

1. Write a shell script to clean up the log

#! /bin/bash

#进入要清理文件的路径

Cd/home/weblogic/bin

#echo "Please clear Startserver1.log and StartWebLogic.log"

#将文件内容清空

>startserver1.log

>startweblogic.log

Cd/home/weblogic/logs/tafs

#将文件内容清空

>send.log

#进入要清理文件的路径

Cd/home/weblogic/server1/logs

Number of files #统计当前目录下所有名称中含有 "Access.log0"

num1= ' Ls|grep access.log0|wc-w '

#判断num1是否大于0, the deletion is greater than 0

If [$num 1-gt 0];then

Files #删除所有文件名中含有 "Access.log0"

RM access.log0*

Fi

2. Place the shell script file anywhere on the Linux system and modify the file execution permissions: chmod +x file name

3, create a timed task: the current user of the Linux system (that is, the currently logged on user, and the user has proposed their own schedule crontab) execution: Crontab–e, and then edit in the Open file: */5 * * * *, Save and exit

4. Execute script: Go to the path where the script is located, execute./clearlog_135.sh

Scheduled cleanup of disk log steps under Linux

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.