user353829
user353829

Reputation: 1434

Cron compress files

I would like to introduce a Cron tak that will 'gzip' files with the following rule:

  1. Locate files in a folder name '/log' (can be located anywhere in the filesystem) and

  2. gzip files, older than 2 days, that have './log' in the file name handle

I have written a the script below - which does not work - am I close? What is required to make it work? Thanks.

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

Upvotes: 0

Views: 4197

Answers (2)

amphetamachine
amphetamachine

Reputation: 30623

In my crontab, I call:

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

In my ~/.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
}

Upvotes: 1

Ben Jackson
Ben Jackson

Reputation: 93860

The -name argument takes a glob. Your command would only match files literally named .log. Try -name "*.log".

Upvotes: 0

Related Questions