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/

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

  • 相关阅读:
    1.Angular的架构模型
    最受欢迎的14款主流渗透工具,流行至今
    当今破解密码涉及的思路方法总结
    Windows权限提升基础知识和命令
    同形异义字:看我如何拿到TaoBao.com的解析权
    【浅谈web安全】大企业安全:从员工下手
    PHPcms9.6.0任意文件上传漏洞直接getshell 利用教程
    【MD5解密】免费帮大家解MD5
    【社会工程学】打脸社工所谓的社工六人组社工帝
    震惊!WIN2003存在后门大全,提权成功率高
  • 原文地址:https://www.cnblogs.com/standby/p/6843500.html
Copyright © 2011-2022 走看看