Manage the periodic logs

Jul 25, '08 07:30:02AM

Contributed by: BjarneDM

There has been some discussion here about the periodic maintenance tasks and making them run:

10.4: Reschedule periodic maintenance tasks
A simple shell script to run system maintenance tasks

What hasn't so far been addressed is the logs themselves. I got very interested in these as I suddenly (under 10.4) couldn't account for 5GB on my hard disk. It turns out that the primary culprit was the daily.out log file that had simply grown out of all proportions. The periodic logs are never cleaned up, and thus just grow in size each and every time the periodic maintenance tasks are run. For example:

[21:02:42@/]$ ls -alOFG /private/var/log/*.out
-rw-r--r--  1 root  wheel  - 509376 17 Jul 03:15 /private/var/log/daily.out
-rw-r--r--  1 root  wheel  -    676  1 Jul 07:52
/private/var/log/monthly.out
-rw-r--r--  1 root  wheel  -  10023 12 Jul 03:25
/private/var/log/weekly.out
I did a clean install of 10.5 Leopard in November 2007, so in a little over half a year, the daily.out log has grown in size to 0.5GB. So in the time before 10.6 Snow Leopard comes out, it'll grow to about 1.5GB in size. I do know that hard drive space is cheap these days, but still...

I've found two ways of handling this (there are of course more solutions -- find the one that suits your needs).

Solution #1: Don't log -- let's be honest, who actually reads these logs? Run the following as root (sudo). This will redirect the output from the periodic tasks into the computational equivalent of a black hole:

sed -E -n -e '/_output/p' /private/etc/defaults/periodic.conf | sed -E -e 's!".*"!"/dev/null"!' /private/etc/periodic.conf
rm /private/var/log/*.out
Solution #2: Only keep the last log, just in case you need it. Save the following script somewhere (remember to chmod +x the script) and then link to it in three places. Here's the script:
[07:42:52@Scripts]$ cat deleteOut.bash
#!/bin/bash

#
# delete the old log file
#

where=$(pwd)
echo rm /private/var/log/${where#*/}.out
The script finds out from where it's been run from, and on the basis of this, deletes the appropriate log file. Thus, the script is generic and I don't have to maintain more than one version of it. Here are the links to create:
sudo ln -s ~bjarne/Scripts/deleteOut.bash /private/etc/periodic/daily/000.deleteOut
sudo ln -s ~bjarne/Scripts/deleteOut.bash /private/etc/periodic/weekly/000.deleteOut
sudo ln -s ~bjarne/Scripts/deleteOut.bash /private/etc/periodic/monthly/000.deleteOut
[robg adds: I haven't tested this one.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080716233104998