Does logrotate depend on cron?

ling picture ling · Nov 12, 2014 · Viewed 8k times · Source

in the logrotate manpage, they say:

"Normally, logrotate is run as a daily cron job".

Does that mean that logrotate uses cron (or is executed by cron)? If so, does that mean that if I don't configure a cron job via crontab (for instance), logrotate will not work?

Answer

Victor Wong picture Victor Wong · Sep 3, 2018

You CAN run logrotate manually WITHOUT cron.

logrotate <configuration file>

However if you want to run logrotate on a scheduled basis, yes you will need cron.

Your package manager should create a default schedule in /etc/cron.daily/logrotate that runs logrotate with the default /etc/logrotate.conf configuration. You can also place your custom configurations in /etc/logrotate.d/ since the default configuration has a line that include all configurations in this directory.

include /etc/logrotate.d

If you want to run logrotate with a custom schedule, you can place your cron job in /etc/cron.d/.

For example, this would trigger logrotate using /etc/custom-logrotate.conf configuration every day at two o'clock.

0 2 * * * root /usr/sbin/logrotate /etc/custom-logrotate.conf

Checkout crontab guru if you need help with cron expression.