nginx日志切割脚本
[root@Rsync ~]# cat nginx_log.sh #!/bin/sh Dateformat=`date +%Y-%m-%d` ------->时间 Basedir="/var/log/nginx" ---->nginx目录 Nginxlogdir="$Basedir/wwwlog" ----->nginx日志目录 Logname="access_www" ------>nginx日志名称 [ -d $Nginxlogdir ] && cd $Nginxlogdir||exit 1 ---------->如果存在目录则切换进去 [ -f ${Logname}.log ]||exit 1 /bin/mv ${Logname}.log ${Dateformat}_${Logname}.log ----->修改名称 /etc/init.d/nginx reload >/dev/null 2>%1 ------>reload #$Basedir/sbin/nginx -s reload ------>编译指定目录reload即可
查看
[root@Rsync ~]# ls /var/log/nginx/wwwlog/ 2015-12-27_access_www.log 2015-12-28_access_www.log access_www.log [root@Rsync ~]#
00 00 * /bin/sh /data/nginx_log.sh
如果需要小时或者分钟切割则修改计划任务时间和脚本中时间格式即可!