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