アウトプットができる技術者に

it's a time to take a new step !

圧縮Scriptサンプル

sapmle1

30日経過したファイルを圧縮して、arcchiveディレクトリへ

find log -maxdepth 1 -mtime +30 -type f | xargs -r gzip
find log -maxdepth 1 -name "*.gz" | xargs -r -i mv {} log/arch
sample2

30日経過したファイル(複数)を1つに圧縮して、archiveディレクトリへ

find log -maxdepth 1 -mtime +30 -name "*.log" -printf "%f " |\
xargs tar --remove-files -zcvf log/arch/all_log.tar.gz -C log
sample3

30日経過したファイルを ファイル名で判別して、archiveディレクトリへ
ファイル形式 :: exe_{yyyymmdd}.log

# date threshold  for archive
ymd_th=`date -d"30 day ago" +"%Y%m%d"`
echo "ymd_th=${ymd_th}"

for path in `find log -maxdepth 1 -name "exe_*.log"`
do
    f=`basename ${path}`
    ymd=${f:4:8}
    if [ ${ymd} -le ${ymd_th} ] ; then
        echo "archive ${path}"
        gzip ${path}
        mv ${path}.gz log/arch
    fi
done