自动压缩文件

[root@BMS006 ~]# cat /shell/compress_applogs.sh
#!/bin/bash
set -x
#Author:welsey
#Date:2011/11/25
LOGFILE_DIR=/data/applogs
CurYear=`date +%Y`                       
CurMonth=`date +%m`  
CurDay=`date +%d`
echo $CurDay
GetYear="$CurYear"
GetMonth="$CurMonth"
GetYesterday="`expr $CurDay - 30`"
hostlist="BMS001 BMS002 BMS004 BMS010 BMS014 BMS016 BMS017 BMS020 BMS024 BMS025"
for host in $hostlist
  do
Dir=$LOGFILE_DIR/$host/$GetYear/$GetMonth/$GetYesterday
    cd $Dir
      filenamelist=`cd $Dir;ls`
    for filename in $filenamelist
     do
     echo $filename
        tar zcvf $filename.tar.gz $filename
       rm -rf $filename
     done    
 done

[root@BMS006 ~]# cat /data/applogs/gzip.sh
#!/bin/sh
set -x
LOGFILE="/tmp/gzip.log"
DIR="/data/applogs"

cd $DIR
for i in `find ./ -type f -mtime +30 | grep BMS | grep -v gz | grep log`
do

    echo $i >> $LOGFILE
    gzip $i
done
exit




#for i in `cat logall.txt `
#do
#    cd $i  
#    gzip local0.log
#    gzip local1.log
#    gzip local2.log
#    gzip local3.log
#    gzip local4.log
#    gzip local5.log
#    gzip local6.log
#done

原文地址:https://www.cnblogs.com/lubing666666/p/4402663.html