日志清理

复制代码
1.由于java项目问题,如下路径会生成以时间格式命名的目录,目录下存在大量的log日志。

/data/applogs/xxl-job/jobhandler/2020-08-03

#!/bin/bash
# File Name: delete_log.sh
# Version: V1.0
# Author: Songyifei
# Organization: www.apolls.cn
# Created Time : 2020-08-03 11:31:56
# Description:
#############################################################
Path=/data/applogs/xxl-job/jobhandler/
time=`date +%Y-%m-%d`
webhook='https://oapi.dingtalk.com/robot/send?access_token=87553735f7b1c338839c4c5fd7dc388a586df67920f1e1a48ea8487bea8492b7'
a=True
b=False
host=`ifconfig eth0 |awk -F '[ :]+' 'NR==2 {print $3}'`
myPath="/server/tmp/"
if [ ! -d ${myPath} ];then
mkdir -p ${myPath}
else
echo dir exist
fi
yum -y install rsync
#for i in `find ${Path}${time} -name *.log`;
for i in `ls ${Path}${time}`
do 
rsync --delete-before -a -H --progress --stats ${myPath} ${Path}${time}
if [ $? -ne 0 ];then
c=`echo $b`
else
c=`echo $a`
fi
done


function SendMsgToDingding() {
curl $webhook -H 'Content-Type: application/json' -d "
{
'msgtype': 'text',
'text': {
'content': '告警主题:$Path${time}日志清理 \n主机IP: $host\n Status: ${c} \n 触发动作: Delete \n '
},
'at': {
'isAtAll': true
}
}"
}

SendMsgToDingding

 
复制代码

 

posted @   地铁昌平线  阅读(200)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示