4.3. Scheduling Tasks

 < Day Day Up > 

Like other flavors of Unix, Mac OS X uses cron to schedule tasks for periodic execution. Each user's cron jobs are controlled by configuration files that you can edit with crontab -e. (To list the contents of the file, use crontab -l.)

4.3.1. Periodic Jobs

In Mac OS X Tiger, the global crontab (/etc/crontab) has been replaced with three launch daemons. The original crontab looked like this:

     15 3 * * *       root    periodic daily     30 4 * * 6       root    periodic weekly     30 5 1 * *       root    periodic monthly 

But now, each line is replaced by a file in /System/Library/LaunchDaemons (com.apple.periodic-daily.plist, com.apple.periodic-weekly.plist, and com.apple.periodic-monthly.plist) that uses the StartCalendar tag to specify when it is to be run. For example, here is the com.apple.periodic-daily.plist file:

     <?xml version="1.0" encoding="UTF-8"?>     <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.     com/DTDs/PropertyList-1.0.dtd">     <plist version="1.0">     <dict>             <key>Label</key>             <string>com.apple.periodic-daily</string>             <key>ProgramArguments</key>             <array>                     <string>/usr/sbin/periodic</string>                     <string>daily</string>             </array>             <key>LowPriorityIO</key>             <true/>             <key>Nice</key>             <integer>1</integer>             <key>StartCalendarInterval</key>             <dict>                     <key>Hour</key>                     <integer>3</integer>                     <key>Minute</key>                     <integer>15</integer>             </dict>     </dict>     </plist> 

These three launch daemons run the scripts contained in subdirectories of the /etc/periodic directory: /etc/periodic/daily, /etc/periodic/weekly, and /etc/periodic/monthly. Each of these directories contains one or more scripts:

     /etc/periodic/daily/100.clean-logs     /etc/periodic/daily/500.daily     /etc/periodic/monthly/500.monthly     /etc/periodic/weekly/500.weekly 

By default, the launch daemons runs them in the wee hours of the night. If your Mac is not usually turned on at those times, you could either edit the com.apple.periodic-*.plist files or remember to run them periodically using the following syntax:

     sudo periodic daily weekly monthly 

As you'll see in Chapter 5, it is vitally important that you run these jobs to ensure that your local NetInfo database is backed up.

You should not modify these files, because they may be replaced by future system updates. Instead, create a /etc/daily.local, /etc/weekly.local, or /etc/monthly.local file to hold your site-specific cron jobs. The cron jobs are simply shell scripts that contain commands to be run as root. The local cron jobs are invoked at the end of the 500.daily, 500.weekly, and 500.monthly scripts found in the /etc/periodic subdirectory.

     < Day Day Up > 

    Mac OS X Tiger for Unix Geeks
    Mac OS X Tiger for Unix Geeks
    ISBN: 0596009127
    EAN: 2147483647
    Year: 2006
    Pages: 176

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net