Extension attribute results disappear after unknown time period

rstraka
New Contributor

Hey Everyone,
I've created a few extension attributes to check for the presence of virtual machines on a computer. One is the "VMware - Virtual Machine List" extension created from the Casper template while the others are simple "if, then" statements checking for files with a .vmx extension (see below for an example). The "VMware - Virtual Machine List" extension only populates if the user manually checks in with Casper via Self Service. The other extension attributes seem to populate at random. Sometimes showing the result value and other times not. All computers are checking in as expected. Basically it seems like the result values are being purged but I'm not sure why. Is there a default cycle time for these values? Also, shouldn't the VM list populate without manually running a check in? Any ideas?

#!/bin/sh
set -e
#script to check for presence of virtual machines on a computer
#script is written for a Casper extension attribute

#check in the default vm folder for files with ".vmwarevms" file extension and pass into "vm" variable 
vm=$(find ~/Documents/Virtual Machines.localized ( -name "*.vmx" ))

if [ -z "$vm" ]; then
    #if the "vm" variable is null return "UNDEFINED"
    echo "<result>UNDEFINED</result>"
else
    #if the "vm" variable is not null return "VM"
    echo "<result>VM</result>"
fi
2 REPLIES 2

rstraka
New Contributor

Digging around more in our Casper settings. I'm wondering if the extension attribute data is cleared when the scheduled time to run the script comes around (ie. during inventory update) but the computer is off at that time. Anyone know if that is the expected behavior?

mm2270
Legendary Contributor III

No, that is not expected behavior, and that has nothing to do with it. The data for a computer will remain static for a fairly long time in the JSS if the Mac isn't being used. We have some machines that haven't "checked in" in a year +, usually because they were decommed and we were never told. Looking at the records in the JSS, most, if not all of the Extension Attribute info and other inventory data is still there, just very old information.

The issue I see with your EA script above is the use of the ~/Documents/ path. You can't use ~ in an EA script because these scripts all get run as root, so you're asking the script to check the /private/var/root/Documents/ directory for a VM, which obviously doesn't make sense. My guess is you really want to check the logged in user's Documents directory, or possibly all local account's Documents directories.
That actually might explain why it only populates with correct info if the user runs a check-in through Self Service.

I would look around on here at the many other threads that discuss how to get a list of user folders, or the logged in user and check that path instead of trying to use ~ in your script. There are plenty of discussions on that topic. Using ~/ is never going to work right for you.