Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use the plutil program to test for corrupt preferences System
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...]
    •    
  • Currently 2.50 / 5
  You rated: 2 / 5 (6 votes cast)
 
[22,281 views]  

Use the plutil program to test for corrupt preferences | 11 comments | Create New Account
Click here to return to the 'Use the plutil program to test for corrupt preferences' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use the plutil program to test for corrupt preferences
Authored by: Collapse on Dec 14, '03 03:59:51AM

Just run it with "sudo", then it will check every users .plists. And it won't report any files as damaged, just because of missing permissions to scan the files.
Oh, and Little Snitch's (one of my favorites!) preferences seems to be saved in a non-standard way, as they will be reported as "The file is not UTF-8, or in the encoding specified in XML header if XML." - no matter if I trashed them an scan the new-created ones.



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: ssevenup on Dec 15, '03 07:26:37PM
Oh, and Little Snitch's (one of my favorites!) preferences seems to be saved in a non-standard way, as they will be reported as "The file is not UTF-8, or in the encoding specified in XML header if XML." - no matter if I trashed them an scan the new-created ones.

Complain to the author.

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.

[ Reply to This | # ]

Use the plutil program to test for corrupt preferences
Authored by: gunnmjk on Dec 14, '03 04:49:09AM

Uhm, sorry, but how do you create a shell script?



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: jedik on Dec 14, '03 12:40:23PM

Basically, you must open Terminal.app and use a text editor like "pico", "vi" ou "emacs" to enter the text and save it to a file (in that case, it was suggested "plist_chk.sh"). Then use the "chmod" commad to make it executable, and move it to the right place, like /usr/local/bin. You can do it graphically, using TextEdit and Finder as well, but the complete explanation would be much more longer. ;)

---
:: Jedi Knight ::
-- Mac Rules! --



[ Reply to This | # ]
Any way to purposefully corrupt a plist?
Authored by: jscotta on Dec 14, '03 10:52:40AM

Anyone know how to purposefully corrupt a plist so that specific issues can be tested with the utility?

---
Windows because I have to. OS X because I want to.



[ Reply to This | # ]
Any way to purposefully corrupt a plist?
Authored by: zacht on Dec 14, '03 03:30:47PM

Well, the crude way would be to use a text editor and corrupt away to your heart's content. :-)

This probably won't work, but maybe you could try force-quitting while the app's prefs panel is open?

zach



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: wgscott on Dec 14, '03 11:21:12PM

Replace /Users with ~/Library/Preferences
and it will just check them in your own directories.

It reported several errors for me:

zsh-% plist_checker.sh
/Library/Preferences/DirectoryService/ContactsNodeConfig.plist:
stream had too few bytes
/Library/Preferences/DirectoryService/ContactsNodeConfigBackup.plist:
stream had too few bytes
/Library/Preferences/DirectoryService/DirectoryService.plist:
stream had too few bytes
/Library/Preferences/DirectoryService/DSLDAPv3PlugInConfig.plist:
stream had too few bytes
/Library/Preferences/DirectoryService/SearchNodeConfig.plist:
stream had too few bytes
/Library/Preferences/DirectoryService/SearchNodeConfigBackup.plist:
stream had too few bytes
/Users/wgscott/Library/Preferences/IM_Installer.plist:
stream had too few bytes



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: aranor on Dec 15, '03 01:30:44AM

I don't know about the IM_Installer.plist (perhaps it has the same problem as Logitech Control Center in that the file is empty?), but the DirectoryService stuff simply requires that you run it as root, i.e. with sudo.



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: Collapse on Dec 15, '03 01:44:35AM

Try to run it with "sudo". Then it won't report those files as damaged, because it can't access them...



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: ssevenup on Dec 15, '03 07:22:51PM

The "stream had too few arguments" messages are mostly because the file is either zero length or has practically nothing in it. Since this is inavlid xml format the utility is doing exactly what it's supposed to. It's incumbent upon the user to identify these files and ignore the messages or delete the files (could be a waste of time if they just get recreated).

--MM


---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
Use the plutil program to test for corrupt preferences
Authored by: cyberwoozle on Mar 10, '04 12:57:44PM
I'm assuming that the "stream has too few bytes" error is not actually an error, merely an indication of an empty file...

anyone tried the xerces method posted on MacinTouch - it seems to give a whole lot more detail that plutil...

David...

[ Reply to This | # ]