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?
The system runs logrotate on a schedule, usually daily. On most distributions, the script that runs logrotate daily is located at /etc/cron. daily/logrotate .
By default, the installation of logrotate creates a crontab file inside /etc/cron. daily named logrotate. As it is the case with the other crontab files inside this directory, it will be executed daily starting at 6:25 am if anacron is not installed.
logrotate succeeds when manually run as root, but fails with "Read-only file system" when run by logrotate. service.
Normally, logrotate is run as a daily cron job. It will not modify a log more than once in one day unless the criterion for that log is based on the log's size and logrotate is being run more than once each day, or unless the -f or --force option is used. Any number of config files may be given on the command line.
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.
Yes, normaly, cron executes logrotate on a daily base. I 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With