您的位置:首页 > 运维架构 > Apache

apache的特大日志的分隔脚本

2016-07-14 16:41 525 查看
最后进行了改良,将参数整理在了一起,最后的结果如下:

工作中遇到了apache的特大日志造成了系统空间大,自己写了一个脚本,解决了日志的分割和删除问题。

最后进行了改良后的程序,将参数整理在了一起,最后的结果如下:

#this shell script used to avoid the apache log to grow so big.
#Author: Lion Lan At: 2016/7/14

#!/bin/sh
#Log's path
logPath=/usr/local/tomcat/logs

#Log's filename
logName=catalina.out

#Log's URL
logURL=$logPath/$logName

#Step1: copy the logfile to log.bak-today'date.
bakFile=$logURL.bak-$(date +%Y%m%d)
#bakFile=$(echo $bakFile | sed -e 's/[ ][ ]*//g')

cp $logURL $bakFile

#Step2: clear the content of the log file.
> $logURL

#Step3: find the unecessary bak log files and deletes.
find $logPath/ -type f -mtime 14 -name "$logName.bak-[0-9]*" | xargs rm -rf


这是测试时写的脚本

#this shell script used to avoid the apache log to grow so big.
#Author: Lion Lan At: 2016/7/14

#!/bin/sh
#Log's path
logPath=/etc/httpd/logs

#Log's filename
logName=access_log

#Log's URL
logURL=$logPath/$logName
echo $logURL

#Step1: copy the logfile to log.bak-today'date.
bakFile=$logURL.bak-$(date +%Y%m%d%l%M)
bakFile=$(echo $bakFile | sed -e 's/[ ][ ]*//g')
cp $logURL $bakFile

#Step2: clear the content of the log file.
> $logURL

#Step3: find the unecessary bak log files and deletes.
find $logPath/ -type f -mmin +7 -name "*bak-[0-9]*" -exec rm -rf {} \;

写在crontab中

0 0 * * * sh /usr/local/tomcat/logs/seperateLog.sh 1>/dev/null 2>&1

最后进行了改良,将参数整理在了一起,最后的结果如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: