1 Star 5 Fork 14

zyh / jd-base

加入 Gitee
与超过 600 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rm_log.sh 1.55 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
evine 提交于 2021-01-21 22:58 . 优化
#!/usr/bin/env bash
## Author: Evine Deng
## Source: https://github.com/EvineDeng/jd-base
## Modified: 2021-01-21
## Version: v3.2.4
## 判断环境
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
## 导入配置文件
. ${ShellDir}/config/config.sh
## 删除运行js脚本的旧日志
function Rm_JsLog {
LogFileList=$(ls -l ${LogDir}/*/*.log | awk '{print $9}')
for log in ${LogFileList}
do
LogDate=$(echo ${log} | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
if [[ $(uname -s) == Darwin ]]
then
DiffTime=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "${LogDate}" +%s)))
else
DiffTime=$(($(date +%s) - $(date +%s -d "${LogDate}")))
fi
[ ${DiffTime} -gt $((${RmLogDaysAgo} * 86400)) ] && rm -vf ${log}
done
}
## 删除git_pull.sh的运行日志
function Rm_GitPullLog {
if [[ $(uname -s) == Darwin ]]
then
DateDelLog=$(date -v-${RmLogDaysAgo}d "+%Y-%m-%d")
else
Stmp=$(($(date "+%s") - 86400 * ${RmLogDaysAgo}))
DateDelLog=$(date -d "@${Stmp}" "+%Y-%m-%d")
fi
LineEndGitPull=$[$(cat ${LogDir}/git_pull.log | grep -n "${DateDelLog} " | head -1 | awk -F ":" '{print $1}') - 3]
[ ${LineEndGitPull} -gt 0 ] && perl -i -ne "{print unless 1 .. ${LineEndGitPull} }" ${LogDir}/git_pull.log
}
## 删除空文件夹
function Rm_EmptyDir {
cd ${LogDir}
for dir in $(ls)
do
if [ -d ${dir} ] && [[ $(ls ${dir}) == "" ]]; then
rm -rf ${dir}
fi
done
}
## 运行
if [ -n "${RmLogDaysAgo}" ]; then
Rm_JsLog
Rm_GitPullLog
Rm_EmptyDir
fi

评论 ( 0 )

你可以在登录后,发表评论

1
https://gitee.com/zyh196463/jd-base.git
git@gitee.com:zyh196463/jd-base.git
zyh196463
jd-base
jd-base
v3

搜索帮助

161121 f78d6d6f 1850385 154831 86f8c370 1850385