apache的特大日志的分隔脚本

来源:互联网 发布:数据整理软件 编辑:程序博客网 时间:2024/05/17 04:20

最后进行了改良,将参数整理在了一起,最后的结果如下:
工作中遇到了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 pathlogPath=/usr/local/tomcat/logs#Log's filenamelogName=catalina.out#Log's URLlogURL=$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 pathlogPath=/etc/httpd/logs#Log's filenamelogName=access_log#Log's URLlogURL=$logPath/$logNameecho $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



最后进行了改良,将参数整理在了一起,最后的结果如下:
0 0
原创粉丝点击