Skip to content

Instantly share code, notes, and snippets.

@linuxkathirvel
Last active December 7, 2020 07:36
Show Gist options
  • Save linuxkathirvel/309a52aa2623a6b2d064eacbbda90a11 to your computer and use it in GitHub Desktop.
Save linuxkathirvel/309a52aa2623a6b2d064eacbbda90a11 to your computer and use it in GitHub Desktop.
How to execute logrotate every hour?

How to execute logrotate every hour?

The 'time based'(hourly, daily, weekly, monthly) and 'size' baesd execution frequencies are available in the logrotate.. Logrotate is configurated to run daily default. There is no option to run logrotate like every 5 minutes, 30 minutes. We can configure logrotate to like every 5 minutes, 30 minutes using manualy crontab entry.

Logrotate configuration file of /etc/logrotate.d/rsyslog

/var/log/syslog
{
        rotate 3
        maxsize 5M
        missingok
        notifempty
        delaycompress
        compress
        postrotate
                /usr/lib/rsyslog/rsyslog-rotate
        endscript
}

/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
        rotate 3
        maxsize 2M
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                /usr/lib/rsyslog/rsyslog-rotate
        endscript
}

Crontab entry to run logrotate to every five minutes

You can configure the normal crontab settings here.

Create state file to store the state of rotated files

sudo touch /var/lib/logrotate/customizedlogrotatestatus

To run every 5 minutes

sudo crontab -e
*/5 * * * * /usr/sbin/logrotate /etc/logrotate.conf --state /var/lib/logrotate/customizedlogrotatestatus

To run every hour

sudo crontab -e
0 * * * * /usr/sbin/logrotate /etc/logrotate.conf --state /var/lib/logrotate/customizedlogrotatestatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment