MacJanitor: System Maintenance on Your Schedule

MacJanitorAs a UNIX administrator, I appreciate the BSD underpinnings of OS X. Many of the tools I use in my every day work are included in the OS, and can be managed in the same way as any of my Production servers.

The casual OS X user may not have intimate knowledge of the inner-workings of the terminal and may need to run any of a number of maintenance tasks or scripts that require access to the terminal and a knowledge of the structure of the filesystem. Enter Mac Janitor.

Mac Janitor is a great small application that exemplifies minimalism. Comprised of six small icons, you can run a number of the regular system maintenance scripts on command. The interface is clean and gives you quick access to its core functionality. There is also a small lock icon which prevents you from accidentally clicking one of the action icons until you’re ready. Documentation, however, is basic and if you’re performing the functions provided by MacJanitor, it helps to have a knowledge of what’s going on “under the covers”.

Macjanitor Screen

The “Action” Icons
Referring to when these scripts normally run, the action icons are across the top of the main interface window in decreasing order of frequency: Daily, Weekly, Monthly, All Tasks. This refers to the schedule that the UNIX Cron subsystem follows in executing each set of tasks. While easy to use and understand what is happening generally, it also helps to understand the specific functions being performed.

Daily
The daily script which is run internally is one of the most feature complete, running a large array of maintenance functions on command.

By selecting the daily icon, you are executing a script in the /etc/daily location on disk. This is a symbolic link (sort of like an alias or a shortcut) to a script residing in the location /etc/periodic/daily/500.daily. Reviewing this script, it is a Bourne Shell script that bills itself as “Removing scratch and junk files”, which is precisely what it does.

First, it looks into the /var/rwho directory for output from a configured rwho subsystem. Rwho is a feature like the “who” command (used to list currently logged in users on the system) but for all machines on the local network. If it finds output there, it removes all files that have not been modified in the last 7 days from this location.

Next, it peers into the /tmp directory (a location for temporary files used by the OS and various applications on the system) and removes all files that have neither been modified or changed in the last 3 days as well as any directories that have not changed in the last 24 hours.

If your machine receives Faxes, the script also has something for you. It looks into your scratch fax directory ( /var/spool/fax ), removing all scratch fax files more than a week old.

Finally, the script prunes system logs based on function. System accounting gets pruned to 21 days, and Netinfo Data gets backed up. The mail queue (if you are running local mail) gets checked, disks get looked at, and basic network connectivity is checked. Syslog is rotated and restarted as well as cleared and a security audit is run and emailed to the root user.

Note that there are a few other checks that get run, but are run on an “if this exists, then run it” type basis. These are /etc/daily.local and /etc/security, and since some systems contain them and some do not, they are out of the scope of this article.

Weekly
The weekly tasks run by MacJanitor are a different class of task, as you will see. Instead of log removal and truncation as the primary tasks, the weekly tasks revolve around the updating of important databases in the BSD subsystem. By clicking on the “Weekly” icon, you invoke the /etc/weekly script which is a symbolic link to /etc/periodic/weekly/500.weekly.

First, the script looks at the locate database and updates it to the most current system state. What is “locate” you may ask?

Much in the way Spotlight searches your hard drive and finds files and or partial file names you put in it’s dialog window, OSX has a command known as “locate”. Locate’s main function is to respond with a full path to any file you are searching for. To perform this, locate makes a database of all files in the system and their location. When you use the terminal command “locate “, the output is simply an answer to a query to the locate database. However, since the filesystem is constantly changing, you need to have a way to keep track of those changes. To accomplish this, the system runs a script (/usr/libexec/locate.updatedb). When you choose the “weekly” icon, one of the functions performed is the update of this database.

Next in the weekly tasks is the makewhatis function. The whatis function allows you to ask a database similar to locate’s what a file is or does. The man page (system documentation) for the whatis command explains:

“whatis searches a set of database files containing short descriptions
of system commands for keywords and displays the result on the standard
output. Only complete word matches are displayed.”

Executing the weekly tasks also updates this database to make sure it is in synch with the actual current state of the filesystem, assuring proper functionality of the whatis command.

Finally, the system logs get rotated, compressed and truncated as well as set to the proper ownerships and permissions and the weekly.local script is run (if you have created it).

Monthly
Last but not least, the monthly icon executes the /etc/monthly script which is linked to /etc/periodic/monthly/500.monthly. The monthly script assures that any fax logs are rotated, compresses, rotates and truncates the system logs, and runs your monthly.local. One difference from the other tasks is that monthly accounting (from the UNIX system accounting subsystem) gets run, the wtmp and install.log files get archived & rotated, and all remaining logs not handled before are rotated in a similar fashion.

All Tasks
As can be expected, the “All Tasks” icon makes sure all the above get run at once. Since you are updating some very large databases with this command, depending on your system specifications and available memory, it can take quite some time to run all these tasks at once, so be patient before trying to cancel or move on to something else. (Note: on my Macbook Pro Core2 Duo with 2GB Ram, this process took roughly 9 minutes. YMMV)

The “Service” Icons
To the right of the interface, there are two service icons titled “Cancel” and “Clear”. The Cancel button will allow you to interrupt processing of any of the features you are currently running. In my testing I was able to cancel all three individual types of runs as well as the “All Tasks” run. In all cases, there was a short delay after pressing “Cancel” before the task ended, and I regained control of the program.

The gray area below these icons is the “console”. As the various processes run, the output of their functions gets sent to this window. The clear icon gives you the ability to clear the console screen for clarity.

Conclusion
MacJanitor is a useful little utility, should you need to regain some space or just to do some routine maintenance and rebuild the locate and whatis databases.

MacJanitor is one of many utilities developed by Brian Hill that can be found on his software page. It is currently at version 1.3 and is freeware. Be sure to have a look at the rest of Brian’s software, and if you find something you can use, please support Brian by registering with him to help encourage developers such like him to keep producing quality Mac software.

Comments

3 Responses to “MacJanitor: System Maintenance on Your Schedule”

  1. Peter on September 27th, 2007 7:45 am

    This is one of many apps that do maintenance tasks ‘by hand’, but I prefer Macaroni :

    http://www.atomicbird.com/macaroni

    Although it’s not free, you can put it in your start-up items and then forget all about it. How’s that for user-friendly ?

  2. JohnD on September 27th, 2007 11:11 pm

    Nice review – informative, just enough detail to pique my interest, and well-written. Thanks for the info!

  3. Karl Jolley on October 12th, 2008 9:02 am

    There are several similar, but I like the ease and completeness of this one. It does all of the normal routine maintenance, when I want it done.
    If I need some other kind of maintenance done, which is nearly never, I use something appropriate to that issue do own Techtool Pro.

    Mac-Janitor is my primary maintenance tool.

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!