全部博文(89)
分类: LINUX
2009-06-25 14:12:04
##################
#
# 安装
#
##################
# debian
aptitude install cronolog
# 源码 默认安装就可
##################
#
# 配置
#
##################
# 具体 cronolog 程序路径 当以 whereis 查看为准
# 如 apache log,修改如下
CustomLog "|/usr/bin/cronolog /data/logs/access_%Y-%m-%d.log" combined
ErrorLog "|/usr/bin/cronolog /data/logs/errors_%Y-%m-%d.log"
##################
#
# lograte.sh
#
##################
#!/bin/bash
## Get date for today. Mode is 20060820 . Today gets is yestoday logs file,the file name is access_2006-08-19.log
dt=$(date -d yesterday +%Y-%m-%d)
## zip logs file
cd /data/logfile
zip -r ./access_${dt}.log.zip ./access_${dt}.log
zip -r ./errors_${dt}.log.zip ./errors_${dt}.log
## delete yestoday log file
rm -rf access_${dt}.log
rm -fr errors_${dt}.log
## delete zip file for 5 days ago
find /data/logfile/ -name access_*.zip -mtime +5 -exec rm -fr { } \;
find /data/logfile/ -name errors_*.zip -mtime +5 -exec rm -fr { } \;
# or
# find /data/logfile/ -name access_*.zip -mtime +5 |xarge -r rm -rf
# find /data/logfile/ -name errors_*.zip -mtime +5 |xarge -r rm -rf
##################
#
# crontab
#
##################
# 每日凌晨两点执行
# crontab -e
0 2 * * * /path/ziplog.sh