#!/bin/bash
#大于xx G
pd_log_size=$(du -sh `grep '/log' \`ps -ef|grep mongo|grep -v grep|awk -F' ' '{print $10}'\`|cut -d'"' -f2`|awk -F' ' '{print $1}'|grep G|cut -d'G' -f1)
#大于xx M
#pd_log_size=$(du -sh `grep '/log' \`ps -ef|grep mongo|grep -v grep|awk -F' ' '{print $10}'\`|cut -d'"' -f2`|awk -F' ' '{print $1}'|grep M|cut -d'M' -f1)
#logname=$(basename $(grep '/log' `ps -ef|grep mongo|grep -v grep|awk -F' ' '{print $10}'`|cut -d'"' -f2))
log_full_pwd=$(grep '/log' `ps -ef|grep mongo|grep -v grep|awk -F' ' '{print $10}'`|cut -d'"' -f2)
log_pwd=$(dirname "$log_full_pwd")
if [ -z "$pd_log_size" ]; then
echo "变量为空,退出脚本。"
exit 1
fi
if [ $pd_log_size -gt 20 ]; then
lz4 $log_full_pwd >${log_full_pwd}_`date +%Y%m%d_%H%M%S`.lz4
:>$log_full_pwd
fi
find $log_pwd -type f -name "*.lz4" -mtime +7 -exec rm {} \;
06 0 * * * source /etc/profile ; cd /data/clear_log && /bin/bash clear_log.sh
标签:cut,grep,log,MongoDB,pwd,awk,归档,print,日志 From: https://www.cnblogs.com/hmysql/p/18420234