shell脚本--删除存储相关内容脚本

工作中删除存储关联内容的shell脚本,记录在这里!
需求:
1.判断如果不是定义的常量相关内容删除;
2.查找删除30前的内容;

#!/bin/sh

list_alldir(){
    a1="face"
    a2="persistence"
    a3="reserved_*"
    a4="skyDrive"
    for file2 in `ls -l $1`
    do
        if [ x"$file2" != x"." -a x"$file2" != x".." ];then
            if [ -d "$1/$file2" ];then
                echo $1/$file2 | grep -q  -e $a1 -e $a2 -e $a3 -e $a4
                if [ $? -eq 0 ];then
                   echo $1/$file2"不能删除!";
                else
                   echo $1/$file2"可以删除!";
                   find "$1/$file2" -mtime +30 -name '*.*'  -print
                   find "$1/$file2" -mtime +30 -name '*.*' -exec rm {} \;
                fi
            fi
        fi
    done
}
#list_alldir  /var/ftp/file | egrep -v '(face|persistence|reserved_*)'

list_alldir  /var/ftp/file

猜你喜欢

转载自blog.csdn.net/xzm5708796/article/details/83794675