Wednesday, November 12, 2008

Geek Out Time: Do It Yourself Setup For Running Repair Permissions Automatically

Running Repair Permissions Automatically

Repairing permissions in Leopard is an important part of keeping a your Mac running smoothly. It's like making sure your tires are at the right pressure, you'll avoid problems and maybe even reduce your carbon footprint (not really, but I couldn't resist the Obama reference).

What Repair Permissions Does: Repair Permissions is part of the Disk Utility application that is installed on every Mac and is in the Applications/Utilities folder. Leopard has an internal database that it uses to keep track of the proper permissions for the System files and folders. When you install or uninstall a program, the System permissions might be left in a state that is not correct. It might not cause problems immediately, but later on applications might have trouble saving preferences or updating or just have instability issues.
Now you can startup Disk Utility and select your main system disk and click on the button to run Repair Permissions but you have to remember to do that on a periodic basis. It's a good idea to run it after you have installed or uninstalled a lot of applications. It also a good idea to run Repair Permissions before and after a Mac OS X Update (i.e. updating from 10.5.5 to 10.5.6).

Here's how to enable your Mac to run Repair Permissions on a regular basis. This is going to require the use of the Terminal application, so be warned, if you don't know what that is it's probably not a good idea to do this yourself.

Built-in Periodic Tasks:
Leopard already runs periodic tasks, daily, weekly, and monthly. The are normally run in the middle of the night, if you leave your Mac running overnight. If you turn off your Mac at night, the tasks still get run, they are just run the first few minutes after you turn your Mac back on.
We are going to take advantage of this built-in feature to run Repair Permissions on a weekly basis. If you don't install or uninstall applications on a regular basis, you could easily change the procedure below to run Repair Permissions on a monthly basis instead.
We are going to create a one line script that will run Disk Utility and Repair Permissions and give the script a special name that will Leopard will recognize. Leopard runs multiple tasks on a daily, weekly, and monthly basis and has the scripts predefined. We DON"T want to change these scripts to include our command line because the predefined script might be over written by a Mac OS X update and our modifications would be lost.

The Local Boys:
Apple has enabled a way to allow custom tasks to be done right after the predefined tasks are completed. This allows you to create any script and run the commands in that script on a daily, weekly, and monthly basis, just by naming the script appropriately and putting it in the correct System folder. To get the script to run on a daily basis, just make sure the name is daily.local, on a weekly basis, weekly.local and on a monthly basis, monthly.local. The .local extension tells Leopard that this is a custom file for this installation of Leopard.
The file needs to be placed in the /etc directory of the system disk and set with the appropriate permissions to execute.

The Gory Details:
  1. To do this procedure you need to have administration rights on your Mac.
  2. Open the Terminal application in the Utilities folder.
  3. Enter the following commands:
    • sudo pico /etc/weekly.local
    • enter your login password
    • In the pico editor enter the following single line of text
      • diskutil repairpermissions /
    • Press control-x and then the y key to save the file
    • You should now be out of the pico editor and back to your command line prompt. Enter this command.
    • sudo chmod 755 /etc/weekly.local
    • You may not have to enter your password again. This command set the execute permissions for the script.
    • Note: Name the script file monthly.local if you want Repair Permissions done monthly.
  4. Quit the Terminal program
  5. You are done!
Now Repair Permissions will run on a weekly (or monthly) basis. The output of the script will be saved in the weekly.log or monthly.log file. You can see this log file by running the Console application in the Utility folder. To see the log file make sure you can see the log list by clicking on Show Log List, and then open the LOG FILES list. In this list open the /var/log section. Scroll down and click on weekly.log or monthly.log depending on what you setup. You should be able to see the output of the Repair Permissions command. You will have to wait a week or a month to see the output depending on the date the last tasks were run.

Blogged with the Flock Browser

No comments: