zoukankan      html  css  js  c++  java
  • 清理脚本

    #!/bin/bash
    # Author      : standby@gmail.com
    # Date        : 2018-02-27
    
    NGX_CONF="/usr/local/nginx/conf/nginx.conf"
    
    # Get the dev which contains ./liveroot/ 
    function get_point()
    {
        arr=(`df -HT |grep -v 'Filesystem' |grep -E '[0-9]{1,2}T' |awk '{print $NF}'`)
        for dev in ${arr[*]}
        do
            [ -d $dev"/liveroot/live" ] && point=$dev && break
        done
        echo $point
    }
    
    # Start here...
    point=$(grep '/liveroot;' $NGX_CONF |awk -F / '{print "/"$2}')
    if [ ! -z "$point" ]
    then
        res=$(echo $point |grep -v ' ' |wc -l)
        [ $res -eq 0 ] && point=`get_point`
    else
        point=`get_point`
    fi
    
    # [live] Touch the stream-name.data file to avoiding deleted.
    for i in $(find $point/liveroot/live -type d ! -name "*mon" |awk -F / '{print $5}')
    do
        [ -f $point"/liveroot/live/"$i"/"$i".data" ] && touch $point/liveroot/live/$i/$i.data
    done
    # [tslive] Touch the stream-name.data file to avoiding deleted.
    for i in $(find $point/liveroot/tslive -type d ! -name "*mon" |awk -F / '{print $5}')
    do
        [ -f $point"/liveroot/tslive/"$i"/"$i".data" ] && touch $point/liveroot/tslive/$i/$i.data
    done
    
    # Clean the old files which contains [*.data | *.pht | *.ts | core.* | temp_* | *.m3u8 | *.log] and keep 3 days only.
    find $point/liveroot/live -ctime +2 -type f -name "*.data" -exec /bin/rm -f {} ;
    find $point/liveroot/live -ctime +2 -type f -name "*.pht" -exec /bin/rm -f {} ;
    find $point/liveroot/live -ctime +2 -type f -name "*.m3u8" -exec /bin/rm -f {} ;
    find $point/liveroot/live -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} ;
    find $point/liveroot/live -ctime +2 -type f -name "core.*" -exec /bin/rm -f {} ;
    find $point/liveroot/live -ctime +2 -type f -name "temp_*" -exec /bin/rm -f {} ;
    #find $point/liveroot/tslive -ctime +2 -type f -name "*.ts" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -path $point"/liveroot/tslive/c1_mon" -prune -o -ctime +2 -type f -name "*.ts" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -ctime +2 -type f -name "*.pht" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -ctime +2 -type f -name "*.m3u8" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -ctime +2 -type f -name "core.*" -exec /bin/rm -f {} ;
    find $point/liveroot/tslive -ctime +2 -type f -name "temp_*" -exec /bin/rm -f {} ;
    # Clean the ffmpeg log and keep 3 days only.
    find $point/liveroot/livelog -ctime +2 -type f -name "*.log" -exec /bin/rm -f {} ;
    
    # [live] Clean the old ./liveroot/live/some_sub_dirs which cleated 5 days ago and has less 5 files contained.
    for i in $(find $point/liveroot/live -ctime +4 -type d ! -name "*_mon")
    do
        [ $i == $point"/liveroot/live" ] && continue
        #ls -ld --time-style=long-iso $i |awk '{print $6" "$7}'
        num=$(ls -l $i |grep '^-' |wc -l)
        [ $num -lt 5 ] && rm -rf $i
    done
    # [tslive] Clean the old ./liveroot/tslive/some_sub_dirs which cleated 5 days ago and has less 5 files contained.
    for i in $(find $point/liveroot/tslive -ctime +4 -type d ! -name "*_mon")
    do
        [ $i == $point"/liveroot/tslive" ] && continue
        num=$(ls -l $i |grep '^-' |wc -l)
        [ $num -lt 5 ] && rm -rf $i
    done
    

      

    作者:Standby一生热爱名山大川、草原沙漠,还有妹子
    出处:http://www.cnblogs.com/standby/

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    UVA 10462 Is There A Second Way Left?(次小生成树&Prim&Kruskal)题解
    POJ 1679 The Unique MST (次小生成树)题解
    POJ 2373 Dividing the Path (单调队列优化DP)题解
    BZOJ 2709 迷宫花园
    BZOJ 1270 雷涛的小猫
    BZOJ 2834 回家的路
    BZOJ 2506 calc
    BZOJ 3124 直径
    BZOJ 4416 阶乘字符串
    BZOJ 3930 选数
  • 原文地址:https://www.cnblogs.com/standby/p/6843500.html
Copyright © 2011-2022 走看看