把 Nginx 的访问日志每天切割一次,保留30天:
[root@localhost ~]$ cat /data/script/cut_nginx_log.sh #!/bin/bash today=`date +%Y%m%d` logDir='/usr/local/nginx/logs' mv $logDir/access.log $logDir/access_${today}.log kill -USR1 `cat $logDir/nginx.pid` find $logDir -maxdepth 1 -mtime +30 -type f -name "access*" -exec rm -rf {} ; &> /dev/null
[root@localhost ~]$ crontab -l
59 23 * * * sh /data/script/cut_nginx_log.sh > /dev/null 2>&1