#!/bin/bash
export LANG=zh_CN.UTF-8
base_log_path="/opt/applog"
part=$(date +%Y)
declare -A apps_map=(
[dubbo]=60
[logs]=7
)
compress_log() {
local path=$1
local part_name=$2
local files=$(find "$path" -type f -name "*$part_name*" -print0 2>/dev/null)
if [ -n "$files" ]; then
while IFS= read -r -d '' file; do
if [[ "$file" =~ .gz$ ]]; then
continue
fi
echo "compressing $file"
gzip -9 "$file" || echo "Error: Failed to compress $file"
done < <(echo "$files")
fi
}
for key in "${!apps_map[@]}"; do
local app_key=$key
local expired_time=${apps_map[$key]}
compress_log "$base_log_path/$key" "$part"
find "$base_log_path/$key" -type f -mtime +$expired_time -print0 | xargs -0 -r rm -f
done
lalalalog
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。