nginx 로그 청소 자동 작업

2992 단어 셸 스 크 립 트
vi /data/aikube/scripts/cut_nginx_log.sh

   :

        #/bin/bash

        #     :         0     

        yesterday=`date -d '-1 day' +%Y-%m-%d`

        #           (      )

        log_bak_path='/data/aikube/nginx-logs'

        # nginx      (      )

        ng_log_path='/usr/local/openresty/nginx/logs'

        #                     

        if [ ! -d ${log_bak_path} ]

        then

          mkdir -p ${log_bak_path}

        fi

        #           

        mv ${ng_log_path}/access.log  ${log_bak_path}/access_${yesterday}.log

        mv ${ng_log_path}/error.log   ${log_bak_path}/error_${yesterday}.log

         

        #   7       

        delday=`date -d '-8 day' +%Y-%m-%d`

        rm -rf ${log_bak_path}/*${delday}.log

         

        #   nginx        

        kill -USR1 `cat ${ng_log_path}/nginx.pid`chmod 777 /data/aikube/scripts/cut_nginx_log.sh

 

 、      

crontab -e

         :

1 0 * * * /data/aikube/scripts/cut_nginx_log.sh

좋은 웹페이지 즐겨찾기