日志压缩脚本

来自linux中国网wiki
跳到导航 跳到搜索


bz2

#!/bin/bash
#27  04  *  * *  /bin/bash /data/mon/bz2yaklog.sh /dev/null 2>&1
#[[email protected]]# 
#0808 在 web2 测试 过了 web1也放上 
#yesderday=`date -d yesterday +%Y%m%d`
yesderday=`date -d -6day  +%Y%m%d`

#for dir in create enter levelup login pay reg start
for dir in create enter levelup login  reg start
do
logdir=/data/logs/yaklog/${dir}/
cd $logdir

#echo $yesderday   >>/data/evan/testshell.log
#tar -cjvf $yesderday.tar.bz2 $yesderday
# tar 压缩并删除源文件
tar -cjvf $yesderday.tar.bz2 $yesderday  --remove-files

cd /data/logs/yaklog
done

zip

[[email protected]]# cat  /data/mon/zipyaklog.sh
#!/bin/bash
#zipyahlog.sh
#17  05  *  * *  /bin/bash /data/zipyahlog.sh 2>&1 >/data/evan/myzip.log
#获取昨天时期:
#yesderday=`date -d yesterday +%Y%m%d`

获取前天日期:`date -d -7day +%Y%m%d` 

#for dir in create enter levelup login pay reg start
for dir in create enter levelup login  reg start
do
logdir=/data/logs/yaklog/${dir}/${yesderday}
cd $logdir

    for file in  `ls $logdir`
    do
        #echo $logdir/$file  >>/data/evan/testshell.log
        gzip -v $file
    done
cd /data/logs/yaklog
done

py 版本

Python日志打包并压缩文件夹