定时清理日志和切割tomcat日志

tomcatLogZip.sh文件内容

#!/bin/sh

#清理30天以前的日志
find /usr/local/edsweb/data/log/ -mtime +30 -name "*.log*" -exec rm -rf {} \;
#执行时间设置为每日23:55跑,压缩转储当天的日志
#当天日期(不是昨天)
yesterday=`date +%Y-%m-%d`

#tomcat日志路径
dir=/home/eds/tomcat-8.5.31-8080/logs

#原日志文件名
file=catalina.out

#复制后的文件名
datefile=catalina."$yesterday".out

#压缩后日志文件名
zipFile="$datefile".tar.gz

if [ -s "$dir"/"$file" ]; then
	cd ${dir}
	
	echo ">>start copy ${dir}/${file}..."
	cp $file $datefile
	echo ">>copy finished!"
	echo > $file
	
	if [ -s "$dir"/"$datefile" ]; then
		cd ${dir}
		
		echo ">>start zip ${dir}/${datefile}..."
		tar -czvPf ${zipFile} ${dir}/${datefile}
	  echo ">>zip finished."
	  rm ${dir}/${datefile}
	  echo ">>file deleted."
	  exit
	else
		echo ">>no have it! ${dir}/${datefile},stop zip!"
	fi
  exit
else
	echo ">>no have it! ${dir}/${file},stop copy!"
fi

操作说明:

创建目录:mkdir /home/eds/logsh
将tomcatLogZip.sh 上传到 /home/eds/logsh
配置crontab : crontab -e
增加配置 : 55 23 * * * sh /home/eds/logsh/tomcatLogZip.sh

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值