#!/bin/bash
dateformat=`date +%Y%m%d`
date_format=`date`
basedir="/usr/local/nginx"
nginxlogdir="$basedir/logs"
log_access="access"
log_error="error"
[ -d $basedir ] && cd $nginxlogdir || exit 1
[ -f ${log_access}.log ] && [ -f ${log_error}.log ] || exit 1
/bin/mv ${log_access}.log ${log_access}_${dateformat}.log
/bin/mv ${log_error}.log ${log_error}_${dateformat}.log
$basedir/sbin/nginx -s reload
sleep 1s
if [ ! -f ${nginxlogdir}/nginx.pid ];then
$basedir/sbin/nginx -s reload
echo "$date_format nginx 第二次重启成功" >> split.logs
exit 0
else
echo "$date_format nginx 第一次重启成功" >> split.logs
dateformat=`date +%Y%m%d`
date_format=`date`
basedir="/usr/local/nginx"
nginxlogdir="$basedir/logs"
log_access="access"
log_error="error"
[ -d $basedir ] && cd $nginxlogdir || exit 1
[ -f ${log_access}.log ] && [ -f ${log_error}.log ] || exit 1
/bin/mv ${log_access}.log ${log_access}_${dateformat}.log
/bin/mv ${log_error}.log ${log_error}_${dateformat}.log
$basedir/sbin/nginx -s reload
sleep 1s
if [ ! -f ${nginxlogdir}/nginx.pid ];then
$basedir/sbin/nginx -s reload
echo "$date_format nginx 第二次重启成功" >> split.logs
exit 0
else
echo "$date_format nginx 第一次重启成功" >> split.logs
exit 0
fi
如有不正确之处,请多多指教!本人小白