Use the plutil program to test for corrupt preferences

Dec 14, '03 02:08:00AM

Contributed by: ssevenup

I was installing the Gnu PGP tools recently, and stumbled onto a command line tool called plutil. This tool will parse any selected files and validate them as well formed XML. It can also convert a specified file from one XML format to another. Anyway, the point here is, it occurs to me that corrupted preference files are likely to fail this validity test.

As such, I created a shell script that parses the two most common places where preference plist files are found, and returns the errors if any are found. Armed with this information, one can decide to trash the files or inspect them. I will be placing this shell script in /usr/local/bin on my client systems, so I can ssh into them and run the script when problems are being reported. Later, I may automate a nightly job that notifies either me or the user.

Code has been revised since hint first published...


#!/bin/sh
# plist_chk.sh

# Check that we are being run as root
if [ $USER != "root" ]; then
  echo "You must be root to execute this script."
  echo ""
  exit 1
fi

find /Library/Preferences -name "*.plist" -print0 | \
xargs -0 /usr/bin/plutil -lint -s
find /Users -name "*.plist" -print0 | \
xargs -0 /usr/bin/plutil -lint -s
[robg adds: Create the script, save it, make it executable, and run it -- it didn't flag anything on my machine, but ... next time I have what I suspect to be a bad preferences problem, I'll try this little routine first to see if it also sees a problem. Just yet another arrow in the troubleshooter's quiver...]

Comments (12)


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