Easier way to limit the size of /var/log

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
User avatar
Pjotr
Level 22
Level 22
Posts: 15765
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland)
Contact:

Easier way to limit the size of /var/log

Post by Pjotr »

If I want to put a cap on the size of /var/log of 50 MB, I put the following line into /etc/logrotate.d/rsyslog:

Code: Select all

maxsize 50M
Which works as intended. But editing by hand is cumbersome. Is there an easier way of setting this? Preferably a one-liner for editing some .conf file (but which one?)....
Tip: 10 things to do after installing Linux Mint 20 Ulyana
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
gm10
Level 20
Level 20
Posts: 10999
Joined: Thu Jun 21, 2018 5:11 pm

Re: Easier way to limit the size of /var/log

Post by gm10 »

Probably not the best idea to try and mask runaway log files with logrotate. Besides, logrotate runs only daily.
User avatar
Pjotr
Level 22
Level 22
Posts: 15765
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland)
Contact:

Re: Easier way to limit the size of /var/log

Post by Pjotr »

gm10 wrote:
Sun Sep 29, 2019 5:48 pm
Probably not the best idea to try and mask runaway log files with logrotate. Besides, logrotate runs only daily.
Well, the Arch wiki seems to suggest that you can set logrotate to run when a specific size has been reached:
https://wiki.archlinux.org/index.php/Logrotate
Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size.
Tip: 10 things to do after installing Linux Mint 20 Ulyana
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
gm10
Level 20
Level 20
Posts: 10999
Joined: Thu Jun 21, 2018 5:11 pm

Re: Easier way to limit the size of /var/log

Post by gm10 »

You're misunderstanding that, that's talking about the configuration options, i'm talking about the default cron job. If you want it to run more often you'd have to schedule it more often. There is no daemon that watches log file sizes in real time.
User avatar
Pjotr
Level 22
Level 22
Posts: 15765
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland)
Contact:

Re: Easier way to limit the size of /var/log

Post by Pjotr »

I have to think about that a bit.... Thanks for responding.
Tip: 10 things to do after installing Linux Mint 20 Ulyana
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Pjotr
Level 22
Level 22
Posts: 15765
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland)
Contact:

Re: Easier way to limit the size of /var/log

Post by Pjotr »

Right... Then these five one-liners seem to be the best approach:

Code: Select all

sudo sed -i 's/rotate 7/rotate 1/g' /etc/logrotate.d/rsyslog

Code: Select all

sudo sed -i 's/rotate 4/rotate 1/g' /etc/logrotate.d/rsyslog

Code: Select all

sudo sed -i 's/weekly/daily/g' /etc/logrotate.d/rsyslog

Code: Select all

sudo sed -i 's/weekly/daily/g' /etc/logrotate.conf

Code: Select all

sudo sed -i 's/rotate 4/rotate 1/g' /etc/logrotate.conf
What do you think?

As an aside: I do realize that this normally won't free up as much disk space as taming the horrible log spamming of systemd, which I've described here:
https://easylinuxtipsproject.blogspot.c ... .html#ID10
(item 10)

But still, it's fun to explore further log taming possibilities. :mrgreen:
Tip: 10 things to do after installing Linux Mint 20 Ulyana
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Post Reply

Return to “Software & Applications”