zoukankan      html  css  js  c++  java
  • 192.168.189.30配置

    crontab -l
    0 */1 * * * /usr/sbin/ntpdate time.tvmining.com && /sbin/hwclock -w >/dev/null 2>&1
    */1 * * * * /opt/script/clear_file.sh 7 >/dev/null 2>&1
    15,45 * * * * /opt/script/clear_path.sh 7 >/dev/null 2>&1
    01 04 * * * /opt/script/clear_m3u8.sh 7 >/dev/null 2>&1

    [root@localhost bin]# vi /etc/cron.d/synctime

    #!/bin/bash

    PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
    n=${1:-7}

    current='/opt/script'
    patharray='/opt/online01/preview /opt/online01/stream'
    year=`date +'%Y' -d "$n day ago"`
    month=`date +'%m' -d "$n day ago"`
    day=`date +'%d' -d "$n day ago"`
    currtime=`date +'%Y%m%d_%H%M' -d "$n day ago"`
    currlog=`date +'delete_%Y%m%d.log' -d "$n day ago"`

    for delfile in `ls $current/delete_*.log`; do
        if [ "$current/$currlog" != "$delfile" ]; then
            rm -f "$delfile"
        fi
    done

    if [ ! -e "$current/$currlog" ]; then
        for datapath in $patharray; do
            find $datapath -maxdepth 3 -type d -name $year >> "$current/$currlog"
        done
    fi


    cat "$current/$currlog" | while read -r line
    do
        if [ -d "$line/$month/$day" ]; then
            `rm -rf $line/$month/$day/*$currtime*` >/dev/null 2>&1
    #        echo "rm -rf $line/$month/$day/*$currtime*" >>"$current/test.log"
        fi
    done

    [root@localhost script]# cat  clear_path.sh
    #!/bin/bash

    PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
    n=${1:-7}

    current='/opt/script'
    patharray='/opt/online01/preview /opt/online01/stream'

    let "nn=$n+1"
    ymd=`date +'%Y/%m/%d' -d "$nn day ago"`

    for delpath in $patharray; do
        for rate in `ls $delpath`; do
            for channel in `ls  "$delpath/$rate"`; do
                if [ -d "$delpath/$rate/$channel/$ymd" ]; then
                    `rm -rf $delpath/$rate/$channel/$ymd` >/dev/null 2>&1
                fi
            done
        done
    done


    for datapath in $patharray; do
        for dd in `find $datapath -maxdepth 5 -mindepth 5 -type d -ctime +$n`; do
            `rm -rf $dd` >/dev/null 2>&1
            #echo "rm -rf $dd >/dev/null 2>&1"
        done

        for ((c=4; c>0; c--)); do
            for dp in `find $datapath -maxdepth $c -mindepth $c -type d`; do
                num=1
                num=`ls $dp | wc -l` >/dev/null 2>&1
                if [ $num -eq 0 ]; then
                    `rmdir $dp` >/dev/null 2>&1
                fi
            done
        done
    done

    [root@localhost script]# cat clear_m3u8.sh
    #!/bin/bash

    PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
    n=${1:-7}

    patharray='/opt/online01/m3u8'
    let "dt=$n+1"

    for datapath in $patharray; do
        for rate in `ls $datapath`; do

            for m3u8 in `find $datapath/$rate -type f -mtime +$dt`; do
                `rm -f $m3u8` >/dev/null 2>&1
            done

            if [ -d "$datapath/$rate" ]; then
                num=1
                num=`ls $datapath/$rate | wc -l` >/dev/null 2>&1
                if [ $num -eq 0 ]; then
                    `rmdir $datapath/$rate` >/dev/null 2>&1
                fi
            fi

        done
    done

  • 相关阅读:
    快速删除段落间多余的空行
    平时一些mysql小技巧及常识
    mysql中常用的控制流函数
    按年、季度、月分组&&计算日期和时间的函数
    Excel通过身份证获取出生年月,性别,年龄,生肖,星座,省份等信息总结归纳
    统计图表类型选择应用总结&表数据挖掘方法及应用
    EXCEL如何提取文字中包含的数字?
    一篇说尽Excel常见函数用法
    RStudio中,出现中文乱码问题的解决方案
    R-RMySQL包介绍学习
  • 原文地址:https://www.cnblogs.com/lubing666666/p/4277362.html
Copyright © 2011-2022 走看看