Cron compress files
I would like to introduce a Cron tak that will 'gzip' files with the following rule:
Locate files in a folder name '/log' (can be located anywhere in the filesystem) and
gzip files, older than 2 days, that have './log开发者_Python百科' 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
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
}
The -name
argument takes a glob. Your command would only match files literally named .log
. Try -name "*.log"
.
精彩评论