LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Centos: Rotate log files at midnight (https://www.linuxquestions.org/questions/linux-server-73/centos-rotate-log-files-at-midnight-924628/)

winairmvs 01-19-2012 10:15 AM

Centos: Rotate log files at midnight
 
I would like to have logrotate execute at midnight for every script in /etc/logrotate.d, but I cannot seem to find any good information on how this is configured.

Toggan 01-19-2012 10:23 AM

By default, logrotate should have a shell script in the /etc/cron.daily directory. If you don't have one, mine looks like this:

Code:

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

This will run a script that has logrotate run with all the configuration settings in /etc/logrotate.conf. Among the settings on that file will be a line that says this:

Code:

include /etc/logrotate.d
You have two options to run it at midnight. You can remove logrotate from the /etc/cron.daily directory and create a cron to run it at midnight, or you can change the schedule for cron.daily to run at midnight. This setting is changed in /etc/crontab.

unSpawn 01-19-2012 10:28 AM

Logrotate scripts are run by the 'logrotate' binary.
Logrotate is run as a /etc/cron.daily/ cronjob.
/etc/cron.daily is referenced in /etc/crontab.
See 'man 5 crontab' for explanation of time and date fields.

winairmvs 01-19-2012 11:05 AM

Quote:

Originally Posted by unSpawn (Post 4578954)
Logrotate scripts are run by the 'logrotate' binary.
Logrotate is run as a /etc/cron.daily/ cronjob.
/etc/cron.daily is referenced in /etc/crontab.
See 'man 5 crontab' for explanation of time and date fields.

I am using Centos 6, which unfortunately has an empty /etc/crontab file by default. I cannot seem to find any documentation that describes how /etc/cron.daily/logrotate is being called in Centos 6.

Edit: After reading the crontab man page it appears that the cron.daily, cron.weekly, and cron.monthly are now called from /etc/anacrontab in Centos 6:

Code:

# /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=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#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

Also in the man page for anacrontab it states:

Quote:

...will start all regular jobs only between 6:00 and 8:00. There is added RANDOM_DELAY which will be maximally 30 minutes. Jobs will be running in queue. After one finish, then next will start.
Which explains why my syslog files were starting and ending at completely random intervals. Seems like a kludgey change.

TenTenths 01-19-2012 11:29 AM

Quote:

Originally Posted by winairmvs (Post 4578990)
Which explains why my syslog files were starting and ending at completely random intervals. Seems like a kludgey change.

So why not try changing RANDOM_DELAY=0 and START_HOURS_RANGE=0-0 to stop the random delay and only start jobs at midnight?


Edit:I've not idea if the START_HOURS_RANGE will work as my servers are all Centos 5.

unSpawn 01-19-2012 04:21 PM

Quote:

Originally Posted by winairmvs (Post 4578990)
I am using Centos 6 (..) Edit: After reading the crontab man page it appears that the cron.daily, cron.weekly, and cron.monthly are now called from /etc/anacrontab in Centos 6

Next time please present complete information and fill in the distribution in your User CP details.


Quote:

Originally Posted by winairmvs (Post 4578990)
Seems like a kludgey change.

There's nothing keeping you from removing Anacron and using Vixie-cron or whatever cron daemon replacement Centos-6 offers.


All times are GMT -5. The time now is 05:03 AM.