How to daily rotate logs, with data from the current day only?
To rotate the log at 11.59pm configure the /etc/crontab file as follow :
59 23 * * * <path_to_logrotate_command> -f <path_to_logrotate_schedule_file> E.g. 59 23 * * * /usr/sbin/logrotate -f /home/foo/logrotate/rotate_nginx
Actually, it would be better to just change the schedule of cron.daily
, to something like this:
$ grep daily /etc/crontab 59 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
Remembering that this will be valid to each script inside /etc/cron.daily
:
$ ls /etc/cron.daily -ltotal 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
But if you need a specific schedule, just for a logrotate rule, the elected answer would be an option.