shell 删除5天前的数据

 

 1 #!/bin/bash
 2 # 删除5天前 prod & test 目录下接口生成的文件 ;
 3 api_csv_path_home=/home/vmuser/linbo/test_upload/data_file
 4 evnArr=(prod test)
 5 apiInfo=(`ls -rt $api_csv_path_home`)
 6 for apiName in ${apiInfo[*]} ;
 7 do  
 8     for evn in ${evnArr[*]} ;
 9     do 
10         FILE_DRI=${api_csv_path_home}/$apiName/$evn
11         for file_pwd in $(find $FILE_DRI -type f -mtime +5);
12         do 
13         #echo $file_pwd
14         file_size=$(du -sh $file_pwd | awk '{print $1}')
15         rm -rf $file_pwd
16         if [ ! -f "$file_pwd" ]; then
17             rm_date=`date +"%F %T"`
18             echo "$rm_date | $file_pwd | $file_size 已删除" 
19         else 
20             rm_date=`date +"%F %T"`
21             echo "$rm_date | $file_pwd | $file_size 删除失败 "
22         fi
23         done
24     done 
25 done 

 

posted @ 2021-01-18 13:17  linbo.yang  阅读(384)  评论(0编辑  收藏  举报