我使用logrotate轮换我的nginx访问日志文件,配置如下。
/var/www/logs/*.log {
daily
missingok
dateext
dateformat _%Y-%m-%d
dateyesterday
rotate 90
compress
delaycompress
compressext
notifempty
create 0640 www-data www-data
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
当cron运行该脚本时,例如在凌晨5点,文件中0点到5点之间的所有日志将被轮换。
是否有机会配置这个?
要在11.59pm旋转日志,配置etccrontab文件如下。
0 0 * * * <path_to_logrotate_command> -f <path_to_logrotate_schedule_file>
E.g. 0 0 * * * /usr/sbin/logrotate -f /var/www/logs/*.log
要在11.59pm旋转日志,配置etccrontab文件如下:0 0 * * * -f E.g. 0 0 * * * usrsbinlogrotate -f varwwwlogs*.log。
要在11.59pm旋转日志,配置etccrontab文件如下。 0 0 * * -f 例如 0 0 * * usrsbinlogrotate -f varwwwlogs*.log。
其实,还不如干脆改变一下时间安排,把 "我 "和 "我 "的名字改成 "我"。cron.daily
变成这样。
$ grep daily /etc/crontab
59 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
记住,这对每个脚本都是有效的。/etc/cron.daily
:
$ ls /etc/cron.daily -l
total 48
-rwxr-xr-x 1 root root 376 nov 20 2017 apport
-rwxr-xr-x 1 root root 1478 abr 20 2018 apt-compat
-rwxr-xr-x 1 root root 355 dic 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 1176 nov 2 2017 dpkg
-rwxr-xr-x 1 root root 372 ago 21 2017 logrotate
-rwxr-xr-x 1 root root 1065 abr 7 2018 man-db
-rwxr-xr-x 1 root root 539 jun 26 2018 mdadm
-rwxr-xr-x 1 root root 538 mar 1 2018 mlocate
-rwxr-xr-x 1 root root 249 ene 25 2018 passwd
-rwxr-xr-x 1 root root 3477 feb 21 2018 popularity-contest
-rwxr-xr-x 1 root root 246 mar 21 2018 ubuntu-advantage-tools
-rwxr-xr-x 1 root root 214 jun 27 2018 update-notifier-common
但是,如果你需要一个具体的时间表,只是为了一个对数旋转规则,当选的答案将是一个选项。