According the the Unix and Linux Administration Handbook and man, logrotate has options for daily, weekly, and monthly, but is there a way to add an hourly option?This blog post mentions you can set size 1 and remove the time option (eg: daily) and then manually call logrotate with cron - I suppose something likelogrotate -f /etc/logrotate.d/my-hourly-filebut is there a more elegant solution for rotating logs hourly?
How can I set up logrotate to rotate logs hourly?
linux;logrotate
Depending on your OS. Some (all?) Linux distributions have a directory /etc/cron.hourly where you can put cron jobs to be executed every hour.Others have a directory /etc/cron.d/. There you can put cron-jobs that are to be executed as any special user with the usual cron-settings of a crontab entry (and you have to specify the username).If you use either of these instead of the standard log rotatation script in /etc/cron.daily/ you should copy that script there and cp /dev/null to the original position. Else it will be reactivated by a logrotate patch-update.For proper hourly rotation, also take care that the dateext directive is not set. If so, by default the first rotated file will get the extension of the current date like YYYYMMDD. Then, the second time logrotate would get active within the same day, it simply skips the rotation even if the size threshold has exceeded.The reason is that the new name of the file to get rotated already exists, and logrotate does not append the content to the existing old file.For example on RHEL and CentOS, the dateext directive is given by default in /etc/logrotate.conf. After removing or commenting that line, the rotated files will simply get a running number as extension until reaching the rotate value. In this way, it's possible to perform multiple rotations a day.