Skip to content

Instantly share code, notes, and snippets.

@cxfksword
Last active August 29, 2015 14:06
Show Gist options
  • Save cxfksword/6c6421c5cb40de9c44dc to your computer and use it in GitHub Desktop.
Save cxfksword/6c6421c5cb40de9c44dc to your computer and use it in GitHub Desktop.
nginx logrotate日志滚动处理
#!/bin/bash
# 更改nginx日志为带日期的文件名
log_dir="/var/log/jbmon/backup/apache"
new_dir="/var/log/jbmon/backup/apache"
date_dir=`date +%Y%m%d%H -d '-1 hours'`
yearstr=`date +%Y%m%d`
FILES=${log_dir}/*.log
for f in ${FILES}
do
# 把log_dir下所有文件名中不包含年份的log文件都改为带日期的文件名
if [[ "${f}" != *${yearstr}* ]]
then
name=$(basename "$f" ".log")
/bin/mv ${f} ${new_dir}/${name}_${date_dir}.log
echo "${f} has been moved to ${new_dir}/${name}_${date_dir}.log"
fi
done
kill -USR1 `cat /var/run/nginx.pid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment