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)

3 Answers 3

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.

1
  • 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. Commented Aug 7, 2017 at 11:59
1

For Debian users, you could think that's it's running at 6.25 (/etc/crontab) but since last few version, it's running at 00.00 and it's configured on systemd !

Old /etc/crontab :

25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

If you wants to change execution time of systemd you have to edit this file : /etc/systemd/system/timers.target.wants/logrotate.timer

by default it's :

[Timer]
OnCalendar=daily

If you wants to run it at 6.20 every day :

[Timer]
OnCalendar=*-*-* 6:20

(then i've rebooted system, but I'm not sure tha'ts necessary !)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .