博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

shell脚本压缩日志文件

Posted on 2022-03-15 20:22  心默默言  阅读(159)  评论(0编辑  收藏  举报
#!/bin/bash

daily_dir=$1 #daily data path, suggest  using absolute path
execute_origin_data_dir=$2 # zipped file store path
date=`date -d "yesterday" +%Y-%m-%d_%H_%M_%S`

if [ "$(ls -A $daily_dir)" ]; then
    tar -czvf $execute_origin_data_dir/EXECUTE_ORIGIN_DATA_$date.tar.gz $daily_dir
    echo "tar file $execute_origin_data_dir/EXECUTE_ORIGIN_DATA_$date.tar.gz success"
    rm -rf $daily_dir/*
    echo "daily_data_path cleaned"
else
    echo "$daily_dir is Empty"
fi