A script to move and file the system logs

Jul 29, '02 08:49:18AM

Contributed by: maclaxguy

If you're like me and were annoyed to find a couple dozen .gz log files in your /var/log directory every time you opened it, than this is a script for you. It runs by cron after the maintenance scripts are run.

Read the rest of the article for the script...

Here's the script:

#Script File to move the gzipped logs
#First, moves all *.gz files from /var/log to /Users/USERNAME/logs/**THECURRENTDATE**
#Then changes the owner to USERNAME and the group to admin

CURRDATE=`/bin/date +%m-%d-%y`
/bin/mkdir /Users/USERNAME/logs/$CURRDATE
/bin/mv /var/log/*.gz /Users/USERNAME/logs/$CURRDATE
/usr/sbin/chown USERNAME /Users/USERNAME/logs/$CURRDATE/*
/usr/bin/chgrp admin /Users/USERNAME/logs/$CURRDATE/*
Replace USERNAME with your actual short user name. Place this script anywhere you want (I put it as /etc/logs). Then, add this to the end of your /etc/crontab file:
35	4	*	*	*	root	sh /etc/logs
Replace "/etc/logs" with wherever you placed the script. Also change the time to about a half an hour after the last maintenance script is run (the first two numbers, in MINUTE HOUR form). Thus, if I listed the contents of /Users/bfoster/logs, I would see this:
[maclaxguy:~/logs] bfoster% ls -F
07-23-02/ 07-24-02/ 07-25-02/
And you'll have the logs from the corresponding dates in each directory. Oh, and you'll also need to create the /Users/USERNAME/logs directory. Hope you find this usefull.

Comments (4)


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