LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-19-2012, 10:15 AM   #1
winairmvs
Member
 
Registered: Aug 2009
Posts: 42

Rep: Reputation: 16
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.
 
Old 01-19-2012, 10:23 AM   #2
Toggan
Member
 
Registered: Oct 2011
Distribution: CentOS 5.9
Posts: 39

Rep: Reputation: 6
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.
 
Old 01-19-2012, 10:28 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 01-19-2012, 11:05 AM   #4
winairmvs
Member
 
Registered: Aug 2009
Posts: 42

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by unSpawn View Post
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.

Last edited by winairmvs; 01-19-2012 at 11:13 AM.
 
Old 01-19-2012, 11:29 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by winairmvs View Post
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.

Last edited by TenTenths; 01-19-2012 at 11:32 AM.
 
Old 01-19-2012, 04:21 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by winairmvs View Post
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 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Rotate log exactly at 12:00 Midnight vinaytp Linux - Newbie 4 09-21-2010 04:27 AM
Log Rotate Configuration on Apache 2.2.15 raj.mahanty@ismt.co.in Linux - Networking 1 09-14-2010 05:10 PM
how to rotate auth.log MrUmunhum Linux - General 3 03-03-2010 07:03 PM
how to shrink and manually rotate log bangsters Linux - General 9 09-20-2009 01:57 PM
Log Rotate MaverickApollo Linux - Software 3 01-19-2004 12:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration