日志分割脚本(按天)示例
这里示例的是nginx日志分割脚本
#!/bin/bash
getdatestring()
{
TZ='Asia/Chongqing' date "+%Y%m%d"
}
datestring=$(getdatestring)
mv /var/log/nginx/access.log /var/log/nginx/access.${datestring}.log
mv /var/log/nginx/error.log /var/log/nginx/error.${datestring}.log
kill -USR1 `cat /var/run/nginx.pid`
find /var/log/nginx/ -name "access.*" -type f -mtime +180 -exec rm {} \; > /dev/null 2>&1
文章目录
关闭