linux 日志分割

[root@clsn6 ~]# vim /etc/logrotate.d/host.access.log
/usr/local/nginx1.19.4/logs/host.access.log {
monthly
rotate 5
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
# /usr/bin/killall -HUP rsyslogd
if [ -f /usr/local/nginx1.19.4/logs/nginx.pid ]; then

kill -USR1 `cat /usr/local/nginx1.19.4/logs/nginx.pid`

fi
endscript
}

logrotate /etc/logrotate.conf
logrotate -vf /etc/logrotate.d/host.access.log

 

分割文件文件名为host.access.log

#!/bin/bash
dir=/usr/local/nginx1.19.4/logs/; #日志路径
file=host.access.log.1; #日志名称
date_file=host.access.log-`date +"%Y%m%d"`; #分割日志文件名称
cd $dir && mv -f $file $date_file; #进行分割

#find $dir -mtime +15 -name "$file-*.log" -exec rm -rf {} \;

 

修改分割文件的文件名

crontab -e
0 0 * * * logrotate -vf /etc/logrotate.d/host.access.log
0 1 * * * sh /usr/local/nginx1.19.4/logs/fenge.sh

跑定时任务

上一篇:mysql 5.7主从复制配置


下一篇:Centos7 logrotate日志切割