标签归档:shell

Linux下定时切割Nginx访问日志并打包压缩的Shell脚本

之前写过这篇文章,但是由于上次的数据丢失故障这篇日志没有了。于是我又重新写了这个脚本,再次贴出来,给大家。

#!/bin/bash
logs_path=/home/logs/www/
arch_log_path=${logs_path}$(date -d "yesterday" +"%Y%m/%d")/

mkdir -p ${arch_log_path}
cd ${logs_path}
for i in `ls *.access.log`
do
        tar zcf ${i}.tar.gz -C ${logs_path} ${i}
        mv ${i}.tar.gz ${arch_log_path}
        rm -rf ${i}
done

kill -USR1 `cat /usr/local/nginx/nginx.pid`

继续阅读