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}/