#!/bin/bash
#不同的项目有不同的路径
array[0]='project1'
array[1]='project2'
array[2]='com/project3'
array[3]='com/phase/project4'
array[4]='project5'
array[5]='com/stor/sproject6'
#项目的主干目录是相同的
RELEASE="/opt/devapps/nexus/sonatype-work/nexus/storage/release/"
for path in ${array[@]};
do
#拼接文件路径
releasepath=${RELEASE}${path}
cd $releasepath
#判断是否存在该目录
if [ $? -eq 0 ];
then
echo $releasepath
echo "Contains file:"
#输出所有的内容
echo *
num=`ls -l | grep '^d' | wc -l`;
#判断文件夹的数量是否超过5个(我只想保留最新的5个文件夹)
if [$num -gt 5 ];
then
#计算超过5个多少
num=`expr $num - 5`
clean=`ls -tr | head -$num | xargs`
echo "will delete file:"
echo ${clean}
#-n1 每次处理1个文件
ls -tr | head -$num | xargs -i -n1 rm -rf {}
fi
fi
done
#!/bin/bash
array[0]='project1'
array[1]='project2'
array[2]='com/project3'
array[3]='com/phase/project4'
array[4]='project5'
array[5]='com/stor/sproject6'
RELEASE="/opt/devapps/nexus/sonatype-work/nexus/storage/release/"
#清空备份文件
BACKUP="/tmp/storage/"
cd $BACKUP
if [ $? -eq 0 ];
then
rm -rf *
fi
#清除超过5个文件之外最老的那些文件
for path in ${array[@]};
do
releasepath=${RELEASE}${path}
cd $releasepath
if [ $? -eq 0 ];
then
echo $releasepath
echo "Contains file:"
echo *
num=`ls -l | grep '^d' | wc -l`;
if [$num -gt 5 ];
then
num=`expr $num - 5`
clean=`ls -tr | head -$num | xargs`
echo "will delete file:"
echo ${clean}
#把文件移动到备份文件夹更安全
ls -tr | head -$num | xargs -i -n1 mv {} $BACKUP
fi
fi
done
crontab -e
0 0 1 * * /opt/project/removecode.sh > /opt/project/remove.log 2>&1 &
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有