一 实验要求
两类机器一共300台,写个脚本自动清理这两类机器里面的日志文件,A类机器日志存放路径很同一,B类机器日志文件存放路径需要用匹配(因为这个目录除了日志外,还有其他文件,不能删除,匹配的时候看用.log)
A类: /opt/cloud/log/ 删除7天前日志
B类: /opt/cloud/instances/ 删除15天前日志
二实验步骤
#!/bin/bash
dir1=/opt/cloud/log/
dir2=/opt/cloud/instance/
if [ -d $dir1 ]
then
find $dir1 -type f -mtime +7 |xargs rm -rf
elif [ -d $dir2 ]
then
find $dir2 -name "*.log" -type f -mtime +15 |xargs rm -rf
fi