logrotate does not rotate at the time specified in crontab

1

I am wondering why logrotate does not rotate my logfiles at the time which it is called through crontab.

My entry in crontab is:

50 2 * * * /usr/sbin/logrotate

Therefore all my logs should be rotated at night at 2:50 am. I receive a status mail from my server that logrotate is called at 2:50, so this seems to be working.

The logs are rotated correctly - but not at 2:50, they are rotated at 9:30 am.

I googled for more the 2h, checked logrotate.conf, my files at logrotate.d, but I can´t find any configuration that could cause that time delay. I would be grateful for a hint about what could cause this behavior and how I can modify it (the settings were configured by my predecessor and I he left me no documentation)

rexemTrebor

Posted 2017-08-07T10:22:51.670

Reputation: 11

Answers

0

OK, I found the problem: There was another entry of logrotate in cron.daily which I did not see lately

So - at least in SLES - you have to config the DAILY_TIME in /etc/sysconfig/cron which is empty by default and should therefore normally run 15min after booting.

Why that was always 9:30? I don´t know, but as I changed it to force running at 4:00 it rotates my logs actually at 4:00.

Got the Information from here: https://lists.opensuse.org/opensuse/2011-09/msg00550.html

rexemTrebor

Posted 2017-08-07T10:22:51.670

Reputation: 11

1

logrotate is controlled by anacron.

Check the configuration of this service in the file etc\anacrontab. For example it can be:

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=10
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-4

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

The line START_HOURS_RANGE=3-4 indicates that anacron will run any time between 3 A.M and 4 A.M. and the line RANDOM_DELAY=10 means that it will add a random time of maximum 10 minutes to the starting time.

You'll need to modify this to make it work at the time that you want.

jcbermu

Posted 2017-08-07T10:22:51.670

Reputation: 15 868

Thanks for the idea - that could have been the reason. But as I use Suse Linux Enterprise Server there is no Anacron or Fcron on my system. – rexemTrebor – 2017-08-07T11:59:33.837