大湖之子 发表于 2018-11-16 13:36:55

nginx日志定期归档脚本

#!/bin/bash  
#nginx下域名access日志切割归档脚本
  
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
  

  
#==================================================Definition array====================================================
  
catalogue=(
  
      www_logs
  
      service_logs
  
      marketing_logs
  
      sdk_logs
  
      mobile_logs
  
      att3_logs
  
      crontab_logs
  
)
  

  
#============================================Definition dealwith log function==========================================
  
function pigeonhole(){
  
cd /DATA/nginx/logs/$1
  
presentpath=`pwd`
  
masterdir=${presentpath##*/}
  
domain=`echo $masterdir | awk -F_ '{print$1}'`
  
if [ -e ./$domain.access.log ];
  
then
  
      cp ./$domain.access.log ./$domain.access-$YESTERDAY.log
  
      tar zcvf ./$domain.access-$YESTERDAY.tar.gz ./$domain.access-$YESTERDAY.log
  
      res=`echo $?`
  
      if [ $res -eq 0 ];
  
                then
  
                echo " " > ./$domain.access.log
  
                rm -rf ./$domain.access-$YESTERDAY.log
  
      else echo "$domain access log compression failed!"
  
      fi
  
else
  
    echo "$domain access log inexistence!"
  
    break
  
fi
  
}
  

  
#==============================================Definition Main function===============================================
  
function ipoll(){
  
      for ((i=0;i
页: [1]
查看完整版本: nginx日志定期归档脚本