You are not logged in.

#1 2009-01-12 05:36:04

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

[SOLVED] logrotate + anacron

I updated my syslog-ng and it recommended logrotate, so on a whim I googled it...  very useful! I would like to cron it like it was in this tutorial: http://www.linux.com/feature/48390 but the trouble is, my laptop would have to be on at midnight. It isn't always, so I googled a little more, and discovered anacron. Ok, it will play missed cron's at boot-up. Perfect!

Trouble is, I have no idea how to set up anacron to automate logrotate. Anyone care to enlighten me? I simply want to keep my system logs tidy and save space. I rarely ever have to look at them, so keeping them for more than a month is rather silly.

Thanks!

Last edited by LeoSolaris (2009-01-25 02:21:51)


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#2 2009-01-12 12:26:11

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: [SOLVED] logrotate + anacron

just put (..., @crond, @anacrond, ...) in the DAEMONS array in your rc.conf. no configuration needed for anacron. it just checks at startup the time when cron was last executed.

so keeping them for more than a month is rather silly.

i keep them for 1 year (52 weeks). you can also compress the logs. logs are only textfiles. my /var/log is under 30mb.

Offline

#3 2009-01-12 19:16:39

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

Ah, alright, so then anacron would use the same setup style as cron, just add 'ana' at the right place?


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#4 2009-01-12 19:30:43

jcolinzheng
Member
From: Cambridge, MA
Registered: 2008-08-06
Posts: 50
Website

Re: [SOLVED] logrotate + anacron

Running it at boot is like what DonVla said.  Be sure to also run it upon resuming from sleep.
/etc/anacrontab is the configuration file, you can check what it contains.

Offline

#5 2009-01-12 19:31:01

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [SOLVED] logrotate + anacron

Maybe it's changed, but the last time I checked anacron is completely independent of cron. You need to specifically assign anacron it's own tasks and it can only guarantee that they will be run at some point during the day.

This is exactly why I create cronwhip: http://bbs.archlinux.org/viewtopic.php?pid=444058

All you need to do is run cronwhip once at startup and it will handle any cronjobs that should have been run while the computer was off.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#6 2009-01-12 19:40:03

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

I think I like cronwhip's idea. I will have to test it out as well. I haven't given up on anacron, and thanks for the location of it's config file, I was looking for it.

Thanks guys. I am going to leave it open till I pick a method, then mark it solved. I did google anacrontab and I think I have a pretty good idea what to do with it to get logrotate... well rotating.


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#7 2009-01-12 19:52:55

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [SOLVED] logrotate + anacron

Good luck getting everything set up the way you want, LeoSolaris.

Just to be clear, cronwhip requires no configuration. It will automatically detect what should have been run by checking the invoking user's crontab.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#8 2009-01-13 00:53:18

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

Xyne wrote:

Good luck getting everything set up the way you want, LeoSolaris.

Just to be clear, cronwhip requires no configuration. It will automatically detect what should have been run by checking the invoking user's crontab.

Thanks, I would have spent a couple of hours looking for the conf! It is a fine and useful program, thank ya for writing it.


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#9 2009-01-14 18:53:17

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

Ok...  I have started to figure out how to get logrotate to work with cron. At least, I have got logrotate to work, and I figured out that I have to use

sudo crontab -e

to get the right place to put cron...  I think.

 0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf

went right in the sudo crontab...

I tested the command

 sudo /usr/sbin/logrotate /etc/logrotate.conf

and it went off without a hitch.

Now the issue is when I use cronwhip with the -n switch (or --dry-run, tried both) it is giving me:

[zeddicus@Archer ~]$ cronwhip --dryrun -v
Use of uninitialized value $hours in addition (+) at /usr/bin/cronwhip line 44.
Use of uninitialized value $mins in addition (+) at /usr/bin/cronwhip line 44.

hmm

I am not sure what I am doing wrong...

Maybe it is because I just made the cron job? or do I need to run cronwhip as root to activate root's crons?


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#10 2009-01-14 19:38:23

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] logrotate + anacron

Edited for clarity:

on my system, i believe by default, logrotate is a daily cron job stored in /etc/cron.daily/ as a script called logrotate

$cat /etc/cron.daily/logrotate
#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf

these cron.daily's should really be run by whatever replacement cronjob manager your bring in as this updates your whatis database among other things

i recommend fcron as a drop in replacement for cron

http://fcron.free.fr/ wrote:

But fcron does not assume that your system is running neither all the time nor regularly : you can, for instance, tell fcron to execute tasks every x hours y minutes of system up time or to do a job only once in a specified interval of time.

pacman will ask you to remove [d]cron when you `pacman -S` in fcron; no worries, anything that was run by cron will be run by fcron.  be sure to replace crond with fcrond in your rc.conf daemons array

fcron also lets you setup specific sets of cron jobs to be run as certain users (this is why i originally googled for it)

sudo fcrontab -u USER -e

will edit any USER's crontab

sudo fcrontab -u systab -e

shows the cron.daily/weekly/etc setups; here's mine:

!mail(no)
&bootrun 01 * * * * /usr/sbin/run-cron /etc/cron.hourly
&bootrun 02 00 * * * /usr/sbin/run-cron /etc/cron.daily
&bootrun 22 00 * * 0 /usr/sbin/run-cron /etc/cron.weely
&bootrun 42 00 1 * * /usr/sbin/run-cron /etc/cron.monthly

the bootrun modifier means if the machine was down during the scheduled runtime, run the job at boot

i think this is what you're looking for

Last edited by brisbin33 (2009-01-14 22:08:02)

Offline

#11 2009-01-15 17:55:44

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

yay Open source! The land of nearly too many options! (nearly)

Thanks guys (or gals)!

I had to reformat, but I am back up and running now, so I get to choose this stuff all over again. (I forgot to save all of this configuring)

Last edited by LeoSolaris (2009-01-15 17:57:38)


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#12 2009-01-25 02:21:30

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

Thanks guys!

I ended up using cronwhip after a little messing with each. All three were handy and I will keep the others in mind if I need some of the functions in them.


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#13 2009-01-25 02:44:01

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [SOLVED] logrotate + anacron

LeoSolaris wrote:

Thanks guys!

I ended up using cronwhip after a little messing with each.

big_smile


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#14 2009-01-25 20:26:28

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: [SOLVED] logrotate + anacron

I liked the simplicity, and I wanted to support a fellow Archer


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

Board footer

Powered by FluxBB