oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Learning the Mac OS X Terminal Learning the Terminal in Jaguar, Part 3

by Chris Stone, coauthor of Mac OS X in a Nutshell

Now that you have the regular maintenance cron jobs running at more reasonable times and emailing you their reports, you would probably like to know what those jobs do, and what the reports tell you.

The Daily Script

To begin, let's have another look at the system crontab, specifically the command for the daily job:

15   3   *   *   *    root    periodic daily

As you might remember, cron uses the periodic utility to run any scripts found in the /etc/periodic/daily/ directory. The real meat of this cron job, then, exists in the files 100.clean-logs and 500.daily. These are both rather complex and would require several articles to explain fully. However, the scripts do contain comments describing each general task, so having a good look at them is informative.

You might also remember that the numbers in the files' names dictate the order in which periodic runs them. Lower numbers run first, and we'll take a look at the first script to run, 100.clean-logs. To view it with more, then, enter:

more /etc/periodic/daily/100.clean-logs

As you look through the script, keep in mind that lines beginning with the #character are ignored as the shell runs through the script. Typically, such lines contain descriptive comments about the script, but they can also be actual command lines that for various reasons are turned off or "commented out."

Mac OS X  in a Nutshell

Related Reading

Mac OS X in a Nutshell
A Desktop Quick Reference
By Jason McIntosh, Chuck Toporek, Chris Stone

Also, the lines beginning with echo provide some of the output that ends up in the reports. For example, these two lines found in 100.clean-logs will begin the daily report with a blank line and the quoted line of text:

 echo ""
 echo "Removing old log files:"

Here's what the top of the file will look like:

Screen shot.

As you probably have guessed by the name of the script, its function is to remove old system logs. In fact, this is a standard BSD script that reads its own configuration information from the main periodic configuration file, /etc/defaults/periodic.conf, which tells this script which directory to clean, and for how long the files can stay there unmodified before being removed.

In Mac OS X's case, the directory it will maintain is /Library/Logs/CrashReporter, and the length of time files can stay there before this script will delete them is 60 days. You can view these settings yourself inside /etc/defaults/periodic.conf. To have more display a file starting from the location of a search string in that file, use more's +/searchstring option.

For example, to view the section of /etc/defaults/periodic.conf that begins with the string 100.clean-logs, use this command:

more +/100.clean-logs /etc/defaults/periodic.conf

You'll see clearly where these settings are defined:

# 100.clean-logs
   # Delete stuff daily
   # Delete under here
   # If not accessed for
   # Don't delete these
   # Mention files deleted

CrashReporter is a process that runs as a background daemon if you've enabled "crash reporting" from within the Console application's preferences. (You'll find Console along with Terminal in /Applications/Utilities.). CrashReporter watches for applications crashing and records their dying gasps, mostly cryptic debugging data, to log files in /Library/Logs/CrashReporter. Upon a first-ever crash, an application gets its own log file in that directory, named applicationname.crash.log. Any subsequent crashes of that application will then get logged to that same file.

If you've often been running an especially troublesome application, it's possible that the /Library/Logs/CrashReporter directory could accumulate some large files. periodic's 100.clean-logs script, then, will look at that directory each time it runs and summarily delete any file inside that hasn't been written to in at least 60 days, since such files would by then be of little value.

The next script to run as part of the daily routine is 500.daily. This is a much longer script; again, I can't fully detail it here, but what follows are the most pertinent highlights. The skipped parts of the script mostly relate to processes not applicable to a "stock" Mac OS X system.

The first section of the script removes "scratch and junk files" from your system. Specifically, some of these items are:

  1. Files existing in /tmp that haven't been accessed or changed in at least the last three days. The /tmp directory contains, among other things, the Temporary Items directory used by many GUI applications, so it's often chock-full of good trash fodder.

  2. Files existing in /var/tmp that haven't been accessed in at least a week, or changed in at least the last three days. Some Unix processes leave junk here as well.

The 500.daily script also performs one of the most important tasks of any in these scripts, that is, backing up your NetInfo database. Actually, the background command in this script doesn't duplicate the database as you can do manually using NetInfo Manager (also found in Applications-> Utilities), but instead dumps the data into a raw file in /var/backups named local.nidump.

Pages: 1, 2

Next Pagearrow