mysql-cut:

error-cut 

#/bin/bash
datetime1=`date -d "1 days ago" +"%Y%m"`
datetime2=`date -d "6 months ago" +"%Y%m"`

errlog='ehrdb.err'
logfile="/var/lib/mysql/${errlog}"
workdir='/data/mysql_err_logs'
archive="${workdir}/${datetime1}"
#自定义
logtime=`date -d "1 days ago" +"%Y%m%d"`
rootid='xjsd'
env='ehr'
logname="${rootid}_${logtime}_${env}_${errlog}"

chmod 644 ${logfile}

mkdir -p ${archive}
cd ${archive}
cp ${logfile} ${logname}
sleep 1
zip -r ${logname}.zip ${logname}
sleep 1
rm -f ${logname}

echo > ${logfile}

rm -rf ${workdir}/${datetime2}

++++++++++++++++++++++++++++++++++++++++++

slow cut

#/bin/bash
datetime1=`date -d "1 days ago" +"%Y%m"`
datetime2=`date -d "6 months ago" +"%Y%m"`

slowlog='ehrdb01-slow.log'
logfile="/var/lib/mysql/${slowlog}"
workdir='/data/mysql_slow_logs'
archive="${workdir}/${datetime1}"
#自定义
logtime=`date -d "1 days ago" +"%Y%m%d"`
rootid='test'
env='test'
logname="${rootid}_${logtime}_${env}_${slowlog}"

mkdir -p ${archive}
cd ${archive}
cp ${logfile} ${logname}
sleep 1
zip -r ${logname}.zip ${logname}
sleep 1
rm -f ${logname}

echo > ${logfile}

rm -rf ${workdir}/${datetime2}
find ${workdir} -type f -name '*log*' -mtime +180 -exec rm -f {} \;
chmod 644 ${logfile}

+++++++++++++++++++++++++++++++++++++++++++

audit-cut

#!/bin/bash
auditlog='server_audit.log'
auditlogdir='/data/auditlogs'
auditlogfile="${auditlogdir}/server_audit.log"
otherlog="${auditlogdir}/otherlogs/"
datetime1=`date -d "1 days ago" +"%Y%m"`
archive="${otherlog}/${datetime1}"
datetime2=`date +%Y%m -d "6 month ago"`

#自定义
logtime=`date -d "1 days ago" +"%Y%m%d"`
rootid='test'
env='test'
logname="${rootid}_${logtime}_${env}_${auditlog}"

chmod 664 $auditlogfile

#创建存储目录
mkdir -p ${archive}
cd ${archive}

#压缩审计日志到指定目录
cat $auditlogfile | grep -v 'update `dd_lock` set `updateDate` =' | grep -v 'update `dd_auth` set `updateDate` =' | grep -v 'UPDATE kq_kqj SET cmd_get_time = SYSDATE()' |grep -v 'update table_check_history set check_result=' > ${logname}
#清空当前日志
echo > $auditlogfile

#格式化日志
if [[ -f ${auditlogdir}/auditlog.py ]];then
        python ${auditlogdir}/auditlog.py ${logname}
fi

#压缩日志
zip ${logname}.zip ${logname}
sleep 1
rm -f ${logname}

#定期清理日志
rm -rf $otherlog/${datetime2}/
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方-phantom

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值