Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

howto limit size of the log files ?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
cc
Posts: 820
Joined: 2005-06-08 19:14

howto limit size of the log files ?

#1 Post by cc »

hi

I have enabled syslog on my mail appliance.

Now I get on my Debian Sarge Stable in:

/var/log/appliance/messages

a very big logfile.

howto limit these log files to 1000k ?

I've looked at man logrotate
I've created following entries in /etc/logrotate.conf :

/var/log/appliance/messages /var/log/appliance/error.log {
weekly
size=+1000k
create 0664 root utmp
rotate 2
}

but it seems, I cannot limit the size.

greetings
cc

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#2 Post by lacek »

I don't think you could limit the size of the log file. What would be the point of that?

Guest

#3 Post by Guest »

Don't know if this is a typo or not, but I think this line...

Code: Select all

size=+1000k
ought to read...

Code: Select all

size 1000k
Also I think you need to remove the line...

Code: Select all

weekly
At least that's what I get from the logrotate man page. Hope that's helpful.

Cheers

cc
Posts: 820
Joined: 2005-06-08 19:14

#4 Post by cc »

hi

I've created a new file in /etc/logrotate.d/appliance with the following entries:

Code: Select all

 
    weekly
    maxage 28
    size=1000k
    create 0664 root utmp
    rotate 2
lacek is is right !
I cannot limit the size, but logrotate runs daily and new file will be created each time.

maybe someone has a perl script to check from cron and limit the size of the logfiles ?

greetings
cc

Guest

#5 Post by Guest »

Read the man page for logrotate, you can limit by size. Your syntax is wrong.

Straight from the man page...
logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.
bold added for emphasis.

Don't give up, and certainly don't write a script when it isn't necessary. (Though it would be an easy script to write.)

cc
Posts: 820
Joined: 2005-06-08 19:14

#6 Post by cc »

Anonymous wrote:Read the man page for logrotate, you can limit by size. Your syntax is wrong.

Straight from the man page...
logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.
bold added for emphasis.

Don't give up, and certainly don't write a script when it isn't necessary. (Though it would be an easy script to write.)
what's wrong in my syntax ?
can you give pls some more details how it should work to limit the size ?
I couldn't find out.

greetings
cc

Guest

#7 Post by Guest »

I think the syntax ought to look like so...

Code: Select all

/path/to/logfile {
    size 1M 
    create 0664 root utmp 
    rotate 2
}
I removed weekly, because you don't want your log rotated weekly, and I removed maxage because it isn't in the documentation.

Do remember that logrotate is usually run as a cron job. This means that logrotate will only notice and rotate a file exceeding your size directive when cron runs logrotate.

Please if someone knows better, speak up. I don't have any logs that get large quickly so I don't haven't been able to test this.

The example of size based rotation on the man page looks like so...

Code: Select all

"/var/log/httpd/access.log" /var/log/httpd/error.log {
    rotate 5
    mail www@my.org
    size 100k
    sharedscripts
    postrotate
        /usr/bin/killall -HUP httpd
    endscript
}

cc
Posts: 820
Joined: 2005-06-08 19:14

#8 Post by cc »

thanks,

I changed the file

cc
Posts: 820
Joined: 2005-06-08 19:14

#9 Post by cc »

sorry I changed the settings, but the log file was not limited to 1M !

the file is 2,5 M now and only at the logrotate scheduled time,
a new file will be created.

greetings
cc

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#10 Post by lacek »

It is because the logrotate setting means "Touch the file if its size is at least 1M". Obviously, logrotate does not run all time, so it can check file sizes when it is run by cron. If the file grown much large in that time, it will back it up, but it won't prevent file to grow large.

Again: you cannot limit the log files' size. Since there is no point at all in doing so, I'm pretty sure that there is no program which would do it...

cc
Posts: 820
Joined: 2005-06-08 19:14

#11 Post by cc »

I know that I cannot limit via logrotate, but the "guest" had other opinion.

I think it's only one solution,
to write a script and check for example every 5 minutes from cron.

greetings
cc

Post Reply