0

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

1
  • 4
    Why are you not using an appropriate tool for this, such as logrotate? Dec 21, 2010 at 0:31

2 Answers 2

1

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
}
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.