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/

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

  • 相关阅读:
    车牌号验证正则验证
    人民币转大写
    Base64 格式图片上传至服务器
    郭博分析modbus主机模式
    解决小BUG的罗列
    写flash时为什么需要先擦除?
    C语言的很吊的printf-----来自一个C语言竞赛题目
    ( # #@ ## 在define中的应用)或( 连接两个字符串或者两个数字、强制转化成单引号、强制转化成双引号 )附加字符串强制转化成数字
    IAR无法goto的解决办法
    link list
  • 原文地址:https://www.cnblogs.com/standby/p/6843500.html
Copyright © 2011-2022 走看看