脚本实现nginx日志切割

#!/bin/bash
# 
datetime=$(date -d "-1 day" "+%Y%m%d")
log_path="/usr/local/nginx/logs"
pid_path="/usr/local/nginx/logs/nginx.pid"
mkdir -p $log_path/backup
if [ -f $pid_path ]; then
        mv $log_path/access.log $log_path/backup/access.log-$datetime
        kill -USR1 $(cat $pid_path)                 ##USR1通常被用来告知应用程序重载配置文件;
        find $log_path/backup -mtime +30 | xargs rm -f
else
        echo "Error,Nginx is not working!"  >> /var/log/messages
fi

 

你可能感兴趣的:(web,网站网络)