Shell Exercises-Cleanup log

Source: Internet
Author: User

Requirements: A total of more than 300 machines, write a script to automatically clean up these two types of machine log files. In the Fortress machine batch release, also want to batch publish to crontab inside.

Class A machine log storage path is very uniform, Class B machine log storage path needs to match with * (because this directory in addition to the log, there are other files, can not be deleted.) *.log available when matching)

Class A:/opt/cloud/log/deleted 7 days ago
Class B:/opt/cloud/instances/deleted 15 days ago

The request is written in a script. Do not consider the operation on the bastion machine, just write out the shell script.




#!/bin/bashdir1=/opt/cloud/instances/dir2=/opt/cloud/log/if [-D $dir 1];then find $dir 1-type f-name "*.log"-mt IME +15 |xargs rm-f elif [-D $dir 2];then find $dir 2-type f-mtime +7 |xargs rm-f fi


This article is from the It Dick thread blog, so be sure to keep this source http://68686789.blog.51cto.com/10438688/1978863

Shell Exercises-Cleanup log

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.