Shell script-automatically delete log files in two types of machines

experiment

Requirements: There
are more than 300 machines of the two types. Write a script to automatically clean up the log files in the two types of machines. Batch release in the bastion machine, but also batch release to crontab.
The log storage path of type A machines is uniform, and the log storage path of type B machines needs to be matched (because there are other files in this directory besides logs, which cannot be deleted. Log can be used when matching)
Type A: /opt/cloud/ log/ delete
category B 7 days ago : /opt/cloud/instances/ delete 15 days ago It is
required to be written in a script. No need to consider the operation on the bastion machine, just write a shell script.

[root@localhost ~]# vim t4.sh
#!/bin/bash
A=/opt/cloud/log
B=/opt/cloud/instances
if [ -d $A ];then
find $A -type f -mtime +7 -exec rm -rf {
    
    } \;
echo "已删除A类7天前日志"
elif [ -d $B ];then
find $B -type f -mtime +15 -name "*.log" -exec rm -rf {
    
    } \;
echo "已删除B类15天前日志"
fi

Guess you like

Origin blog.csdn.net/ZG_66/article/details/108220210