Apache日志分割

  • A+
所属分类:Apache WEB技术
#!/bin/bash
logpath=/home/wwwlogs/ #日志的路径
expred=7 #保存7天前的日志
pid=/usr/local/apache/logs/httpd.pid #httpd pid路径
datetime=$(date -d yesterday +%Y%m%d) #昨天的日期

if [ ! -d ${logpath}oldlog ]; then
mkdir ${logpath}oldlog
fi
mkdir ${logpath}oldlog/${datetime}
mv ${logpath}*.log ${logpath}oldlog/${datetime}/
kill -USR1 $(cat ${pid}) find ${logpath}oldlog -type f -mtime +${expred} -exec rm -f {} \;

保存为apache-log-handle.sh文件,设置crontab执行。

echo '1 0 * * *  /root/sh/apache-log-handle.sh' 

>> /var/spool/cron/root

YaLei

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: