Chinaunix首页 | 论坛 | 博客
  • 博客访问: 381410
  • 博文数量: 89
  • 博客积分: 3176
  • 博客等级: 中校
  • 技术积分: 1205
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-15 10:08
文章分类

全部博文(89)

文章存档

2011年(17)

2010年(19)

2009年(35)

2008年(18)

分类: 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

 

 

 


 

阅读(560) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~