How to use python in Extension Attribute scripts

cnixon14
New Contributor III

I am trying to get info from a plist to see if the machine has any updates pending and I got this so far:
18fca85982574c558406b309504ceb2c

But the returned value is not showing up. What am i doing wrong here? Thanks!

6 REPLIES 6

mm2270
Legendary Contributor III

I'm not sure what the issue would be, since from what I can tell it should be outputting the results in between those <result></result> tags. But, why use python for something this simple? A standard shell script using defaults can do this just as easily.

#!/bin/sh

if [[ $(/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist RecommendedUpdates 2>/dev/null) == "" ]]; then
    /bin/echo "<result>No Updates</result>"
else
    /bin/echo "<result>Updates</result>"
fi

cnixon14
New Contributor III

I have tried using defaults but it doesn't return an empty string. It returns a few lines of empty space that I have tried to trim with this 48870fae3ca24490a936fbd4fafe3d13

but it still says there are "Updates Needed"

mm2270
Legendary Contributor III

You could try this:

/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist RecommendedUpdates | sed 's/)//;s/(//;/^$/d'

That should return a null value if the RecommendedUpdates array is empty or some data if it's not empty. From there the rest of the script should work.

cnixon14
New Contributor III

That appears to have worked. thank you

tlarkin
Honored Contributor

you might have to open the file to read it in python

tlarkin
Honored Contributor

example:

with open('/Library/Preferences/com.apple.SoftwareUpdate.plist', 'rb') as f:
     data = plistlib.load(f)
     print(data)