【问题标题】:Cron compress filescron 压缩文件
【发布时间】:2011-05-28 13:44:24
【问题描述】:

我想介绍一个 Cron tak,它将使用以下规则“gzip”文件:

  1. 在名为“/log”的文件夹中定位文件(可以位于文件系统中的任何位置)和

  2. gzip 文件,超过 2 天,文件名句柄中包含“./log

我在下面写了一个脚本——它不起作用——我关闭了吗?需要什么才能使其工作?谢谢。

/usr/bin/find ./logs -mtime +2 -name "*.log*"|xargs gzip

【问题讨论】:

  • 您为什么不为此使用合适的工具,例如 logrotate?

标签: linux cron gzip logging crontab


【解决方案1】:

-name 参数采用 glob。您的命令只会匹配字面上名为 .log 的文件。试试-name "*.log"

【讨论】:

    【解决方案2】:

    在我的 crontab 中,我调用:

    /usr/sbin/logrotate -s ~/.logrotate/status ~/.logrotate/logrotate.conf
    

    在我的 ~/.logrotate/logrotate.conf 中:

    # rotate log files weekly
    weekly
    
    # keep 4 weeks worth of backlogs
    rotate 4
    
    ## compression
    
    # gzip(1)
    #compresscmd /usr/bin/gzip
    #compressoptions -9
    #uncompresscmd /usr/bin/gunzip
    #compressext .gz
    
    # xz(1)
    compresscmd /usr/bin/xz
    uncompresscmd /usr/bin/xzdec
    compressext .xz
    
    /home/h3xx/.log/*.log /home/h3xx/.log/jack/*.log {
        # copy and truncate original (for always-open file handles
        # [read: tail -f])
        copytruncate
    
        # enable compression
        compress
    }
    
    /home/h3xx/.usage/*.db {
        # back up databases
        copy
    
        # enable compression
        compress
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      • 2019-02-24
      • 2023-03-28
      • 2010-12-14
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多