通过du方式遍历磁盘统计相应域名截图存储容量

#!/bin/bash
domain="xy.push.live.fanxing.com"
current_storage_dir="/data1/worker.snapshotv3.live.xycdn.com/store/"
log_time="date +%F_%T"
date=`date +"%Y%m%d"`
pre_date=`date +"%Y%m%d" -d "1 day ago"`
pre_two_date=`date +"%Y%m%d" -d "2 day ago"`

function write_log() {

        content=$1
        echo "`${log_time}` $1" >>/tmp/du_count_time.log
}

function archive_count() {

for i in `seq 2 13`
do
        if [ -d /data$i/worker.snapshotv3.live.xycdn.com/store ];then
                for date in $(ls /data$i/worker.snapshotv3.live.xycdn.com/store)
                do
                  cd /data$i/worker.snapshotv3.live.xycdn.com/store/$date;ls|grep "$domain" 
                        if [ $? -eq 0 ];then
                                du -sh $domain >>/tmp/du_count.log
                        else
                                echo "the date dir is not exist $domain snapshot"
                                continue
                        fi
                done
        else
               echo "$data$i is not exist $domain snapshot"
               continue
        fi

done
}


function current_count() {
        [ -d $current_storage_dir ] || exit 1
        arr_current_storage=($pre_two_date $pre_date $date)
        for date_dir in ${arr_current_storage[*]}
            do
                cd ${current_storage_dir}${date_dir};ls|grep "$domain" 
                if [ $? -eq 0 ];then
                    du -sh $domain >>/tmp/du_count.log
                else
                    echo "the date dir is not exist $domain snapshot"
                    continue
                fi

            done


}

main() {
#        [ -f /tmp/du_count.log ] && echo -n >/tmp/du_count.log
#       write_log "start count fanxing archive snapshot captity"
#       archive_count
#       write_log "END count fanxing archive snapshot captity"
        write_log "start count fanxing current 3 days snapshot captity"
        current_count
        write_log "end count fanxing current 3 days snapshot captity"
        awk '{sum+=/T/?$1*1024:(/M/?$1/1024:$1)}END{print "Sum="sum"G"}' /tmp/du_count.log

}

main

转载于:https://www.cnblogs.com/dforward2017/p/6872223.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值