首先是日誌定時分割腳本nginx
#@/bin/sh dat=`date +"%Y%m%d" ` mon=`date +"%Y%m"` echo $dat mondir="/usr/openResty/logs/$mon" /bin/echo $mondir #>> /usr/openRest/hello.info if [ ! -x "$mondir" ]; then echo "開始建立日期文件夾" mkdir "$mondir" echo "建立日期文件夾結束" fi #/bin/echo ` ls -al $mon` >> /usr/openRest/hello.info mv /usr/openResty/logs/error_90.log $mondir/error_$dat.log kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid` /bin/echo "done " # >> /usr/openRest/hello.info
其次是按期清理腳本shell
#/bin/sh shellinfo=/usr/openResty/hello.info logdat=` date -d " -1 month" +%Y%m ` /bin/echo $logdat >> $shellinfo lastlogdat=` date -d " -2 month" +%Y%m` /bin/echo $lastlogdat >> $shellinfo logPath="/usr/openResty/logs/" lastlogTar="${logPath}${lastlogdat}.tar.gz" /bin/echo $logPath >> $shellinfo /bin/echo "over" $lastlogTar >> $shellinfo if [ -x "$logPath$logdat" ]; then /bin/echo "開始壓縮上月日誌文件" >> $shellinfo /bin/echo $logPath$logdat "待壓縮的文件夾" >> $shellinfo tar -zcvf $logPath$logdat.tar.gz $logPath$logdat /bin/echo `ls -al /usr/openResty/` >> $shellinfo /bin/echo "換行 開始刪除上個月的文件夾" >> $shellinfo rm -rf $logPath$logdat /bin/echo "換行 刪除上個月的文件夾完畢" >> $shellinfo fi if [ -a "$lastlogTar" ]; then /bin/echo "開始刪除上上個月的日誌壓縮包" >> $shellinfo rm -rf $lastlogTar /bin/echo "刪除上上個月的日誌壓縮包完畢" >> $shellinfo fi
crontab -e 根據須要添加定時任務spa