Author Topic: [How-to] Limit the size of .log files & the journal:  (Read 7440 times)

0 Members and 1 Guest are viewing this topic.

Offline joshua

  • Core Team
  • *****
  • Posts: 986
  • Standing on the shoulders of giants...
  • Branch: unstable
  • Desktop: KDE / OpenBox
  • GPU Card: AMD A6-3420M
  • GPU driver: non-free
  • Kernel: linux310-x86
  • Skill: Guru
[How-to] Limit the size of .log files & the journal:
« on: 12. August 2013, 10:03:34 »
Original tutorial can be found at:
https://wiki.manjaro.org/index.php?title=Limit_the_size_of_.log_files_%26_the_journal



Thanks dcell. :D

I'm glad you have an obsession with loooong command lines. :)

I'll have to incorporate your post into the wiki page (or you are most welcome to do it yourself).

I guess we should get some feedback from people that have used it before putting in the wiki. I'll give it a shot too. Another good thing about having the script there is that people can change the sizes if for some reason they want to.
I actualy hadn't really considered people changing the default values... But with a tad slight modification to the script this can be easily incorporated  ;D. Now it asks for the values the second you start it with an example.
New source code:
Code: [Select]
#!/bin/bash
echo "What size would you like the maximum file size for journald.conf to be? EX. 50M"
read maxsizejournal
echo "what size would you like the maximum file size logrotate.conf to be? EX. 10M"
read maxsizelogrotate


#This one edits the journald.conf file
maxline=`cat /etc/systemd/journald.conf | grep "#SystemMaxUse="`
if [ "$maxline" == "#SystemMaxUse=" ]
then
    sed "s/\#SystemMaxUse=/SystemMaxUse=$maxsizejournal/g" /etc/systemd/journald.conf > /etc/systemd/journald.conf2
    mv /etc/systemd/journald.conf2 /etc/systemd/journald.conf
    echo -e "\njournald.conf has been modified\n"
else
    echo -e "\njournald.conf has been edited already. You'll need to do it manually.\n"
fi

#This one edits the logrotate.conf file
maxline=`cat /etc/logrotate.conf | grep "#size 20M"`
if [ "$maxline" == "#size 20M" ]
    then sed "s/\#size 20M/size $maxsizelogrotate/g" /etc/logrotate.conf > /etc/logrotate.conf2
    mv /etc/logrotate.conf2 /etc/logrotate.conf
    echo -e "logrotate.conf has been modified\n"
else
    echo -e "logrotate.conf has been edited already. You'll need to do it manually.\n"
fi
And I attched a new copy of the script. About the wiki page, You can put it in there if you want. I haven't really had a chance to dabble in the wiki quite yet so it'll more than likely turn out better if you do it  ;).
@dcell: you knew it was going to do this to me didn't you:

Code: [Select]
[handy@jarmano ~]$ logfile.shrinker.sh

journald.conf has been edited already. You'll need to do it manually.


logrotate.conf has been edited already. You'll need to do it manually.

I copied your script, made it executable & executed it. That's why the name has a freckle.
I put it a conditional there so that incase you've already edited it manually in the past then it wouldn't blindly re-edit it just incase someone already had edited it and forgot about it  ;). In the case that they have then it will just exit the script without changing anything. If you want to have a test go with the script then you can set them back to the defaults and it'll run. Also the script will need to be ran as root for it to change the files so you'll need to either "su root" and run it or run it like "sudo bash logfile.shrinker.sh". The default values were by the way

journald.conf:
Code: [Select]
#SystemMaxUse=logrotate.conf:
Code: [Select]
#size 20M
« Last Edit: 26. June 2014, 03:56:03 by aaditya »

Offline blade

  • Jr. Mitglied
  • **
  • Posts: 88
  • Branch: Unstable
  • Desktop: Xfce 4.12.3
  • GPU Card: NVIDIA GeForce GT 650M
  • GPU driver: non-free
  • Kernel: 4.5.x-1-MANJARO
  • Skill: Advanced
Re: [How-to] Limit the size of .log files & the journal:
« Reply #1 on: 12. August 2013, 10:10:07 »
Yes, now it work for me. I have one suggest. Before move this to wiki make this commands more clear. I have to read this several times before I cope what to do. Some people that don't know much about what each script do will have a problem with this and they might do something wrong. Or you can make some automated system to do that and we can just input what size of journal we want.

Offline joshua

  • Core Team
  • *****
  • Posts: 986
  • Standing on the shoulders of giants...
  • Branch: unstable
  • Desktop: KDE / OpenBox
  • GPU Card: AMD A6-3420M
  • GPU driver: non-free
  • Kernel: linux310-x86
  • Skill: Guru
Re: [How-to] Limit the size of .log files & the journal:
« Reply #2 on: 12. August 2013, 10:21:27 »
Yes, now it work for me. I have one suggest. Before move this to wiki make this commands more clear. I have to read this several times before I cope what to do. Some people that don't know much about what each script do will have a problem with this and they might do something wrong. Or you can make some automated system to do that and we can just input what size of journal we want.
Yeah that occured to me when handy pointed it out people probably wouldn't be able to unravel the sed command that easy so in the new script I posted now it asks for user input about the default values  ;). If I were you though I would probably just use the script though instead of those long commands, those were really just kind of for fun really. I'll add some steps for how to use the script I'll post here since while rereading my last post I realize it's kind of hard to understand.

The first thing to do is download the script and note the path for it. Next open a terminal and chmod it so that it can be ran. Assuming that it was saved into your Downloads directory then you can chmod it like this.
Code: [Select]
sudo chmod +x ~/Downloads/logfileshrinkerNow you can run the script. This will also need to be ran as root since it's editing files outside of your home directory.
Code: [Select]
sudo bash ~/Downloads/logfileshrinkerNow the script will be ran and it will ask you for the values you would like to use and give you an example so you know what syntax to use  ;D.

Offline blade

  • Jr. Mitglied
  • **
  • Posts: 88
  • Branch: Unstable
  • Desktop: Xfce 4.12.3
  • GPU Card: NVIDIA GeForce GT 650M
  • GPU driver: non-free
  • Kernel: 4.5.x-1-MANJARO
  • Skill: Advanced
Re: [How-to] Limit the size of .log files & the journal:
« Reply #3 on: 12. August 2013, 10:37:02 »
I run this automated script and it worked. Thanks @dcell. Now you or @handy can put this tutorial and automated script to the wiki so other users can reduce this too much memory consuming journal.

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #4 on: 12. August 2013, 10:55:59 »
I've created the wiki page here:

Limit the size of .log files & the Journal


15-Aug-13: I've reworked the wiki page. The newly entered logrotate section is laid out better, easier to navigate & easier to understand than it was. I will add to it & attempt to clarify it further in the future as I continue testing on my own system, this could go on for a couple of weeks as some of the testing will take that long.

16-Aug-13: Added more to the logrotate section of the wiki page.

31-Aug-15: Corrected the above link to the wiki page.
« Last Edit: 31. August 2015, 08:06:19 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #5 on: 13. August 2013, 10:08:39 »
I'm not happy with this how-to yet (even though it is wikified), I think it can be improved a lot, particularly in the logrotate area, which is a very powerful & somewhat complex (for me) area. I'm working at learning more about this & I'll hopefully be able to post improvements later.
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #6 on: 13. August 2013, 14:49:07 »
I've been doing some research on logrotate & have learned a great deal.

So the following is a basic run down of what I've learned, I just need some time to verify & fine tune it before I incorporate this stuff into the new wiki page.

Please check this out & give me feedback, trial it, feedback here on it, & we can generally raise our understanding of this logrotate stuff.
__________

/etc/logrotate.conf holds general settings for the /usr/bin/logrotate command that are applied to some of the /var/log/ files.

logrotate is called however often it is set to be called. Meaning it can be called from /etc/ cron.hourly, cron.daily, cron.weekly, cron.monthly, cron.yearly, by placing a script that calls it into those the previously mentioned directories that (all but cron.yearly) reside in our /etc/ directory.

Logrotate can also be called to run at any time via crontab .

Apart from anything else that logrotate.conf does, it also runs any scripts that are located in the /etc/logrotate.d which it does through the following command:

Code: [Select]
include /etc/logrotate.d
Some installed applications drop scripts into /etc/logrotate.d to aid in their own maintenance one way or another. We can use another location of our choosing for these or other scripts if we want, we just have to call its path the same way, the following is an example:

Code: [Select]
include /home/handy/.config/mylogrotate
Apart from adding our own scripts to /etc/logrotate.d (or any other path that we have included, we can also add scripts into the previously mentioned /etc/ cron.hourly, cron.daily, cron.weekly, cron.monthly, folders.

So you can see there are multiple ways to call logrotate.

As an example, if we wanted to rotate a particular log file in our /var/log/ directory on a daily basis, keep it for 7 days before it is deleted (meaning there would be 7 separate log files for the week), compress the file but do it on the next cycle, do it in a fashion where the original contents of the file is copied before the original file's contents is deleted, do nothing if the file is empty & if it is missing don't give an error, we should be able to do that with the following:

Code: [Select]
/var/log/messages.log {
 daily
 rotate 7
 compress
 delaycompress
 copytruncate
 notifempty
 missingok
  }

Now if we put the following into a script that holds other blocks that are similar to the above but customised for different files contained in /var/log/ , into the /etc/logrotate.d/ directory & we have /etc/logrotate.conf being called daily, then logrotate.conf will run any scripts that we have in logrotate.d everyday for us & so our will should be done...

That's the plan anyway...
« Last Edit: 14. August 2013, 01:33:50 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #7 on: 13. August 2013, 15:20:49 »
OK, I just ran the following script manually from su it was modified as follows:

Code: [Select]
/var/log/*.log {
 daily
 rotate 7
 compress
 delaycompress
 copytruncate
 notifempty
 missingok
  }

The results look pretty good. 

Tomorrow hopefully the files that I just rotated will become compressed (not that I need them compressed, I just want it to do what I told it to).

I'll need to add the above script to the /etc/logrotate.d directory now for the compression to happen inside of the next 24 hours.

Here's screenshot:

« Last Edit: 13. August 2013, 15:23:45 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #8 on: 13. August 2013, 16:12:59 »
I have modified the wiki page. Now the Logrotate section is more complicated than I want it to be. I'll get to that after sleep. :)
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #9 on: 14. August 2013, 05:49:52 »
I've reworked the wiki page, the newly entered logrotate section is laid out better, easier to navigate & easier to understand than it was. I will add to it & improve it as I continue testing on my own system, this could go on for a couple of weeks as some of the testing will take that long.
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #10 on: 14. August 2013, 06:40:39 »
I just checked & my /var/log directory & it was certainly good to see what it happening in there. There is some inconsistencies in there due to other tests I did yesterday, but the bottom line is that the script that I have placed in the /etc/crond.daily directory is calling the logrotate /etc/logrotate.conf command, which in turn is calling the script that I added to the /etc/logrotate.d directory & that script is doing what it is supposed to. Which is always nice to see when you are a bash script baby like me.

Here's a screenshot of the next phase of the 7 days of keeping daily backups of *.doc files, then compressing those backups on the next cycle & deleting them before they age to 8 days old.

This is the script I have in /etc/logrotate.d
[edit:] I added the comments to make it clearer for the reader /edit

Code: [Select]
/var/log/*.log {   # do all files ending in .log in /var/log/
 daily      # cycle this lot daily
 rotate 7    # keep 7 cycles of rotated backup files
 compress    # compress with the default .gzip , adds .gz extension
 delaycompress    # compress on the next cycle
 copytruncate    # copy contents to new file add .1 .2 ->.7 to file name, then remove contents of original file
 notifempty    # do nothing if file is empty
 missingok    # give no error if file does not exist
  }    # close command sequence

As can be seen from the attached screenshot, I haven't worked out how to deal with the Xorg.0.log files yet?

[edit:] Thinking about it, as X doesn't use logrotate & you don't have any more than the two Xorg.0.log files to look at, then allowing logrotate to keep a weeks worth of Xorg.0.log files is not a bad thing. So that problem was easily solved.
« Last Edit: 15. August 2013, 01:11:20 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #11 on: 14. August 2013, 07:20:49 »
The script (below) running in /etc/cron.daily basically calls the following command in potentially the nicest possible way, I edited last night so that it isn't so diplomatic I'll make it nicer later:

This is the command that the following script calls:

Code: [Select]
logrotate /etc/logrotate.conf
The script in /etc/cron.daily/logrotate that runs the all important above command:

Code: [Select]
#!/bin/sh

# nicenesses range from -20 (most favorable scheduling) to 19 (least favorable)
NICE=19

# 0 for none, 1 for real time, 2 for best-effort, 3 for idle
IONICE_CLASS=1

# 0-7 (for IONICE_CLASS 1 and 2 only), 0=highest, 7=lowest
IONICE_PRIORITY=7

CMD_LOGROTATE="/usr/bin/logrotate /etc/logrotate.conf"

if [ -x /usr/bin/nice ]; then
  CMD_LOGROTATE="/usr/bin/nice -n ${NICE:-19} ${CMD_LOGROTATE}"
fi

if [ -x /usr/bin/ionice ]; then
  CMD_LOGROTATE="/usr/bin/ionice -c ${IONICE_CLASS:-2} -n ${IONICE_PRIORITY:-7} ${CMD_LOGROTATE}"
fi

${CMD_LOGROTATE}

exit 0

The above script (comes with Manjaro) can be placed into any of the /etc/cron.d cron.daily cron.weekly cron.monthly cron.yearly directories & will then run the logrotate /etc/logrotate.conf command that will also run any scripts that are in the /etc/logrotate.d directory. I keep going over this stuff as it is the bottom line of using logrotate (as I see it anyway).

The script, (below), will handle all of the /var/log/*.log files. The faillog & lastlog are not normal log files, they are accessed via Terminal commands of the same name (took me a while to finally learn that):

Code: [Select]
/var/log/*.log {
 daily
 rotate 7
 compress
 delaycompress
 copytruncate
 notifempty
 missingok
  }
« Last Edit: 15. August 2013, 16:27:48 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #12 on: 15. August 2013, 16:21:53 »
I know, I'm slow... I just realised that faillog & lastlog are not really log files, each of them are commands. <doh!>

So I'm going to remove a totally irrelevant previous post or two as they will only cause confusion.

Edited the previous post to make it correct.
« Last Edit: 15. August 2013, 16:28:48 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #13 on: 16. August 2013, 04:43:07 »
OK, I've refined the system some more & applied a simple form of verbose testing from the command line:

To test the following script, which now moves all files compressed by the default .gzip , into the /var/old directory I used the following at the command line after first using the su command & password:

Code: [Select]
logrotate -vf /etc/logrotate.conf
The -vf in the above command are for verbose & force. Verbose prints to the screen everything that the logrotate /etc/logrotate.conf command is doing. Forcing (with the -f) the above command should put all of the log files in sync from now on & remove the inconsistencies of backup number & such that has come about due to my testing various things over the past days.

Here is the current state of my rotate.logs script (/etc/logrotate.d/rotate.logs), I've removed the . before log which should handle the failog & lastlog files for the hell of it:

Code: [Select]
/var/log/*log {
 daily
 rotate 7
 compress
 delaycompress
 copytruncate
 notifempty
 missingok
 postrotate
    mv /var/log/*.gz /var/log/old
 endscript
  }

If you use a postrotate command of any kind, you must use the endscript command after it, or your whole logrotate process will fail. This I know from experience.

The above script now does nearly everything that I want, including cleaning out my /var/log directory of all the compressed backups, which makes it much easier to navigate.

This is what my /var/log looks like now, it shows the currently being used log file & the first uncompressed backup, all of the gziped backups are now in /var/log/old :

Code: [Select]
[handy@jarmano ~]$ ls -l /var/log
total 2564
drwxr-xr-x 2 root  lp       4096 14.08.2013 09:10 cups/
drwxr-xr-x 3 root  root     4096 15.03.2013 10:04 journal/
drwxr-xr-x 2 root  root     4096 16.08.2013 11:54 old/
drwxr-xr-x 2 proxy proxy    4096 17.07.2013 12:52 squid/
-rw-r--r-- 1 root  users       0 16.08.2013 10:18 Xorg.0.log
-rw-r--r-- 1 root  users   23324 16.08.2013 10:18 Xorg.0.log.1
-rw-r--r-- 1 root  users   24001 16.08.2013 00:58 Xorg.0.log.old
-rw-r--r-- 1 root  users       0 28.06.2013 22:10 Xorg.1.log
-rw-r--r-- 1 root  users   19375 04.06.2013 12:39 Xorg.1.log.old
-rw-r----- 1 root  log       278 16.08.2013 12:21 auth.log
-rw-r----- 1 root  log       155 16.08.2013 11:44 auth.log.1
-rw------- 1 root  utmp        0 16.08.2013 11:54 btmp
-rw------- 1 root  utmp        0 16.08.2013 11:54 btmp.1
-rw-r----- 1 root  log        79 16.08.2013 12:01 crond.log
-rw-r----- 1 root  log       330 16.08.2013 11:42 crond.log.1
-rw-r----- 1 root  log      1046 16.08.2013 12:10 daemon.log
-rw-r----- 1 root  log      3138 16.08.2013 11:42 daemon.log.1
-rw-r----- 1 root  log         0 16.08.2013 11:42 errors.log
-rw-r----- 1 root  log       102 16.08.2013 11:42 errors.log.1
-rw-r----- 1 root  log      3525 16.08.2013 12:19 everything.log
-rw-r----- 1 root  log      1000 16.08.2013 11:54 everything.log.1
-rw------- 1 root  root        0 16.08.2013 10:18 faillog
-rw------- 1 root  root   160128 16.08.2013 10:18 faillog.1
-rw-r--r-- 1 root  root        0 15.08.2013 10:45 gufw.log
-rw-r--r-- 1 root  root      662 15.08.2013 10:45 gufw.log.1
-rw-r----- 1 root  log      2400 16.08.2013 12:19 iptables.log
-rw-r----- 1 root  log      1000 16.08.2013 11:54 iptables.log.1
-rw-r----- 1 root  log         0 16.08.2013 10:18 kernel.log
-rw-r----- 1 root  log    367963 16.08.2013 10:18 kernel.log.1
-rw-r--r-- 1 root  root        0 16.08.2013 10:18 lastlog
-rw-r--r-- 1 root  root  1461168 16.08.2013 10:18 lastlog.1
-rw-r----- 1 root  log      1046 16.08.2013 12:10 messages.log
-rw-r----- 1 root  log      3138 16.08.2013 11:42 messages.log.1
-rw-r--r-- 1 root  root        0 16.08.2013 10:18 ntp.log
-rw-r--r-- 1 root  root      738 16.08.2013 10:18 ntp.log.1
-rw-r--r-- 1 root  root        0 16.08.2013 10:18 pacman.log
-rw-r--r-- 1 root  root     1415 16.08.2013 10:18 pacman.log.1
-rw-r--r-- 1 root  root        0 15.08.2013 10:45 pm-powersave.log
-rw-r--r-- 1 root  root    13865 15.08.2013 10:45 pm-powersave.log.1
-rw-r--r-- 1 root  root        0 15.08.2013 10:45 soundon.log
-rw-r--r-- 1 root  root    83606 15.08.2013 10:45 soundon.log.1
-rw-r----- 1 root  log         0 16.08.2013 10:18 syslog.log
-rw-r----- 1 root  log       820 16.08.2013 10:18 syslog.log.1
-rw-r----- 1 root  log         0 14.08.2013 23:01 user.log
-rw-r----- 1 root  log    371615 14.08.2013 23:01 user.log.1
-rw-rw-r-- 1 root  utmp        0 16.08.2013 11:54 wtmp
-rw-rw-r-- 1 root  utmp        0 16.08.2013 11:54 wtmp.1

Here's the /var/log/old :

Code: [Select]
[handy@jarmano ~]$ ls -l /var/log/old
total 700
-rw-r--r-- 1 root users   4888 15.08.2013 10:45 Xorg.0.log.2.gz
-rw-r----- 1 root log      176 16.08.2013 11:42 auth.log.2.gz
-rw-r----- 1 root log     2459 16.08.2013 10:18 auth.log.3.gz
-rw-r----- 1 root log      521 15.08.2013 10:45 auth.log.4.gz
-rw-r----- 1 root log    67346 14.08.2013 23:01 auth.log.5.gz
-rw-r----- 1 root log      859 16.08.2013 10:18 crond.log.2.gz
-rw-r----- 1 root log      415 15.08.2013 10:45 crond.log.3.gz
-rw-r----- 1 root log    16185 14.08.2013 23:01 crond.log.4.gz
-rw-r----- 1 root log    27788 16.08.2013 10:18 daemon.log.2.gz
-rw-r----- 1 root log     6117 15.08.2013 10:45 daemon.log.3.gz
-rw-r----- 1 root log      301 16.08.2013 10:18 errors.log.2.gz
-rw-r----- 1 root log       99 15.08.2013 10:45 errors.log.3.gz
-rw-r----- 1 root log    10267 14.08.2013 23:01 errors.log.4.gz
-rw-r----- 1 root log      181 16.08.2013 11:44 everything.log.2.gz
-rw-r----- 1 root log     1341 16.08.2013 11:42 everything.log.3.gz
-rw-r----- 1 root log   126607 16.08.2013 10:18 everything.log.4.gz
-rw-r----- 1 root log    26510 15.08.2013 10:45 everything.log.5.gz
-rw-r----- 1 root log      181 16.08.2013 11:44 iptables.log.2.gz
-rw-r----- 1 root log    21963 16.08.2013 10:18 iptables.log.3.gz
-rw-r----- 1 root log     1727 15.08.2013 10:45 iptables.log.4.gz
-rw-r----- 1 root log    62252 14.08.2013 23:01 iptables.log.5.gz
-rw-r----- 1 root log    14377 15.08.2013 10:45 kernel.log.2.gz
-rw-r----- 1 root log    87004 16.08.2013 10:18 messages.log.2.gz
-rw-r----- 1 root log    18033 15.08.2013 10:45 messages.log.3.gz
-rw-r--r-- 1 root root      69 15.08.2013 10:45 ntp.log.2.gz
-rw-r--r-- 1 root root   12460 14.08.2013 23:01 ntp.log.3.gz
-rw-r--r-- 1 root root  123175 15.08.2013 10:45 pacman.log.2.gz
-rw-r----- 1 root log      118 15.08.2013 10:45 syslog.log.2.gz
-rw-r----- 1 root log     3556 14.08.2013 23:01 syslog.log.3.gz

The only other change I'd like to make, is to check the /var/log files every hour for their size with a size 2M line, in a modified /etc/logrotate.d/rotate.logs file that will have to be placed into /etc/cron.hourly (I think?). (Or setup to run that often via crontab, dropping it into /etc/cron.hourly is certainly easier.)

Having the log files checked for size every hour will, if something goes haywire in the background on my system & it starts spewing forth repetitive error messages (probably into more than one log file), the size 2M will cause it to be rotated with the oldest file being deleted once it gets to the 8th rotation. & 2MB x 7. of repetitive error should give more than enough clues to go on with when trying to solve the problem's cause.

I'll look into this & post the results when I find out the best way to do it.
« Last Edit: 16. August 2013, 05:08:43 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak

Offline handy

  • Global Moderator
  • *****
  • Posts: 5738
  • Desktop: Openbox 3.6.1-3 & Worker :)
  • GPU Card: intel...
  • GPU driver: open-source
  • Kernel: OpenBSD
  • Skill: Intermediate
Re: [How-to] Limit the size of .log files & the journal:
« Reply #14 on: 16. August 2013, 06:41:30 »
I've looked into running a script hourly & it looks like /etc/cron.d/0hourly is set to run the contents of /etc/cron.hourly . So I've created the following here /etc/cron.hourly/check.log.size :

Code: [Select]
/var/log/*log {
 hourly
 rotate 10
 size 2M
 compress
 delaycompress
 copytruncate
 notifempty
 missingok
 postrotate
    mv /var/log/*.gz /var/log/old
 endscript
  }

The rotate 10 & the size 2M will limit the amount of space taken up by a serious repetitive error problem to a pre-compression size of 20MB per log file effected, as the gzipped history is deleted when it ages beyond 10 rotations.

I'll see how this functions.

[edit:] /var/log/crond.log log says the following, so it should be working fine:

Code: [Select]
Aug 16 12:01:01 localhost CROND[1679]: (root) CMD (run-parts /etc/cron.hourly)
Aug 16 13:01:01 localhost CROND[1736]: (root) CMD (run-parts /etc/cron.hourly)
Aug 16 14:01:01 localhost CROND[1824]: (root) CMD (run-parts /etc/cron.hourly)

The only thing I'm not sure of now, is this. The size ** line takes precedence over the rotation ** line, if both exist. Which begs the question, will the rotation 10 command work & delete any rotations beyond that set number?
« Last Edit: 16. August 2013, 07:02:54 by handy »
The ultimate tyranny in a society is not control
by martial law. It is control by the psychological
manipulation of consciousness, through which reality
is defined so that those who exist within do not even
realize that they are in prison.
  —  Barbara Marciniak