LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-24-2014, 08:03 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
Log rotation time


I am trying to determine the time that my daily (and other) logs were being rotated. I found this:

#/etc/cron.d/anacron: crontab entries for the anacron package

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

30 7 * * * root test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null


My server does seem to be rotating my daily logs at 0730 each morning. Is this where I would change the time for this? How would I do this using the safety of crontab for #/etc/cron.d/anacron?

Could I execute this manually to force a log rotation without ending up with two rotations:

test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null

Thanks.
 
Old 08-25-2014, 03:16 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Assuming this is on Debian 7 Wheezy, logrotate is run by /etc/cron.daily/logrotate. On a system with anacron installed, all the /etc/cron.daily/* scripts are run in lexical order by run-parts as scheduled by /etc/crontab. The default /etc/crontab:
Code:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
The actual time that the /etc/cron.daily/logrotate script starts depends on how long previous corn.daily scripts take to run.
 
Old 08-25-2014, 06:42 AM   #3
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Thanks, I'll have to time this to see what is happening.
 
Old 08-25-2014, 08:47 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
I guess I am going to need explicit instructions on this.

My /etc/cron.d/anacron file:

#/etc/cron.d/anacron: crontab entries for the anacron package

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

30 7 * * * root test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null

My /etc/cron.daily/logrotate file:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Now what do I need to change the times in one or both of these files to change the daily logrotate to 20:30 my local time? Right now it seems to be rotating around 07:45 to 08:00.

Last edited by battles; 08-25-2014 at 08:48 AM.
 
Old 08-26-2014, 12:04 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
First disable the existing /etc/cron.daily/logrotate. A nice way to do so is to rename it as /etc/cron.daily/logrotate.disabled. That way it is easy to restore it if and when you want and clear that it has been disabled.

Then set up a scheduled job to replace it. Three options:
  1. /etc/crontab
  2. root's crontab
  3. An /etc/cron.d file
AFAIK "the Debian way" is to use root's crontab (/etc/crontab is installed by package so best not changed and IIRC /etc/cron.d is intended for packages, not sysadmins to create files in).

As root, use the crontab -e command (taking care not to key r instead of e!) and create a line:
Code:
30 20 * * * /usr/sbin/logrotate /etc/logrotate.conf
EDIT: that's not really your /etc/cron.daily/logrotate file is it?!

Last edited by catkin; 08-26-2014 at 12:05 AM.
 
Old 08-26-2014, 07:29 AM   #6
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Thanks!

Yes, this s what is in my /etc/cron.daily/logrotate:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Last edited by battles; 08-26-2014 at 07:59 AM.
 
Old 08-26-2014, 08:35 AM   #7
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
What is really strange about this is one of my daily file date/tine rotated at 'Tue Aug 26 07:27:34 CDT 2014'. Not 30 7 or 25 6. It looks like the
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
may be triggering the rotate, but at 6:25am? Can't figure.
 
Old 08-27-2014, 05:51 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The contents of your /etc/cron.daily/logrotate are the same as the default /etc/crontab. /etc/cron.daily/logrotate should be:
Code:
#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
The "daily file date/time rotated at 'Tue Aug 26 07:27:34 CDT 2014'. Not 30 7 or 25 6." could be caused by the /etc/cron.daily jobs before logrotate taking around an hour to run.
 
Old 08-27-2014, 06:44 AM   #9
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Ok, thanks. Actually, I had that wrong. My /etc/cron.daily/logrotate is:

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

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

to

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

at one tome, but the rotate never happened. I don't think that I have to reset logrotate after this change with any special restart parameters.

Last edited by battles; 08-27-2014 at 06:53 AM.
 
Old 09-01-2014, 04:04 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You could try restoring the original /etc/crontab and using the technique given in
http://www.linuxquestions.org/questi...8/#post5227301
 
  


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] Default rotation of logins log (/var/log/wmtp) gacanepa Linux - Newbie 2 10-01-2013 06:59 PM
[SOLVED] Log rotation of log files in different directories mahi_nix Linux - Server 7 02-19-2013 05:33 AM
LXer: Latest release of systemd includes time-based log rotation LXer Syndicated Linux News 0 10-24-2012 12:51 AM
How to change Debian log rotation of syslog and daemon.log onmountain Linux - Newbie 2 07-31-2008 02:27 AM
Log Rotation for snort log does not seem to be working CentOS4.5 JasonKretzer Linux - Security 3 06-25-2007 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:49 AM.

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