Hourly rotation of files using logrotate?

LinuxCronRhelLogrotate

Linux Problem Overview


I tried to set up a log rotation of logs files located at /tmp/hr_logs/. For setting up, I used logrotate in linux and I'm able to rotate it on daily basis using the following config in my /etc/logrotate.conf

  /tmp/hr_logs {
  daily
  rotate 4

With this config, file will rotate on daily basis and system will keep 4 copies of the log file appended with date [format: -YYYYMMDD]

Now, I trying to set up a different set of log files which I need to make rotate on hourly basis and for it, i have done the configuration in logrotate.conf:

  /tmp/last_logs {
  hourly
  rotate 4

But this is not at all working? Can anyone please guide me on this please?

Linux Solutions


Solution 1 - Linux

The manpage of logrotate.conf contains an important advice for the hourly option:

> Log files are rotated every hour. Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly.

As pointed out by yellow1pl the solution is to copy the file /etc/cron.daily/logrotate into the /etc/cron.hourly/ directory. This works at least for Debian and possibly some Debian derivates.

Solution 2 - Linux

There is /etc/cron.daily/logrotate script for daily logrotates. However there is no such script by default in /etc/cron.hourly/ directory. Copy this script and it should work fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKishoreView Question on Stackoverflow
Solution 1 - LinuxscaiView Answer on Stackoverflow
Solution 2 - LinuxrsmView Answer on Stackoverflow