码迷,mamicode.com
首页 > 其他好文 > 详细

清理旧数据的小脚本

时间:2017-05-12 01:36:10      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:log   disk   break   style   which   system   exec   containe   script   

 

 1 #!/bin/bash
 2 # Author      : standby
 3 # Date        : 2017-05-09
 4 # Description : Clean the old files and dirs to free the local disk.
 5 #                   - file keep 2 days.
 6 #                   - dir  keep 5 days and less 5 files contained.
 7 
 8 NGX_CONF="/usr/local/nginx/conf/nginx.conf"
 9 
10 # Get the dev which contains ./path/ 
11 function get_point()
12 {
13     arr=(`df -HT |grep -v Filesystem |grep -E [0-9]{1,2}T |awk {print $NF}`)
14     for dev in ${arr[*]}
15     do
16         [ -d $dev"/somePath" ] && point=$dev && break
17     done
18     echo $point
19 }
20 
21 # Start here...
22 point=$(grep /path; $NGX_CONF |awk -F / {print "/"$2})
23 if [ ! -z $point ]
24 then
25     res=$(echo $point |grep -v   |wc -l)
26     [ $res -eq 0 ] && point=`get_point`
27 else
28     point=`get_point`
29 fi
30 
31 # Clean the old files which contains [*.cpp | *.jpg | *.c] and keep 2 days only.
32 find $point/somePath -ctime +1 -type f -name "*.c" -exec /bin/rm -f {} \;
33 
34 # Clean the old ./path/some_sub_dirs which created 5 days ago and has less 5 files contained.
35 for i in $(find $point/somePath -ctime +4 -type d ! -name "*except_dir*")
36 do
37     [ $i == $point"/somePath" ] && continue
38     #ls -ld --time-style=long-iso $i |awk {print $6" "$7}
39     num=$(ls -l $i |grep ^- |wc -l)
40     [ $num -lt 5 ] && rm -rf $i
41 done

 

清理旧数据的小脚本

标签:log   disk   break   style   which   system   exec   containe   script   

原文地址:http://www.cnblogs.com/standby/p/6843500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!