14

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?

ling
  • 9,545
  • 4
  • 52
  • 49

2 Answers2

19

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.

Victor Wong
  • 3,457
  • 1
  • 18
  • 31
1

Yes, normaly, cron executes logrotate on a daily base. It depends on your linux distro, but the normal is to have cron running it.

You can check if have the file /etc/cron.daily/logrotate If thats the case, you distro uses cron to run logrotate.

If you are using docker, this can bring some problem, currently cron doesn't run inside a container.

Gonen
  • 4,005
  • 1
  • 31
  • 39
João Luís
  • 314
  • 2
  • 9