Using File Modification Dates as Version Numbers

dan-snelson
Valued Contributor II

Background

Inspired by John Eberle's, Louise Radifera's and Alex Smith's presentation "Supplementing Jamf's reporting with MunkiReport (JNUC305)" at JNUC 2020, we're now test-driving MunkiReport 5.6.3.4224.

After learning the hard way that a new client installer is needed each time I enabled a new module, I could no longer rely on a Jamf Pro Extension Attribute of munkiReportVersion=$( /usr/bin/defaults read /Library/Preferences/MunkiReport Version ) since every test Mac was already running 5.6.3.4224, but not my latest installer of version 5.6.3.4224.

In early testing, switching to using file modification dates as version numbers seems to be working well.


Extension Attribute

Determine the location of a critical file which is only modified by your installer package and enter its path in the testFile variable. (In this use-case, I decided not to use /Library/Preferences/MunkiReport.plist as I'm purposely modifying scriptTimeOut during testing.)

Next, establish a bogus date for computers which will not have testFile; in this case, I used 2020-01-01 20:01:01.

Create a new Computer Extension Attribute:
- Data Type: Date
- Input Type: Script

#!/bin/sh
# Extension Attribute to detect presence of MunkiReport Runner

# munkiReportVersion=$( /usr/bin/defaults read /Library/Preferences/MunkiReport Version )

testFile="/usr/local/munkireport/munkireport-runner"

if [ -f "${testFile}" ] ; then
    result=$( /bin/date -j -f "%s" "$(/usr/bin/stat -f "%m" $testFile)" "+%Y-%m-%d %T" )
else
    echo "<result>2020-01-01 20:01:01</result>"
fi

echo "<result>$result</result>"

50c9edc48ad041fb8e48a69dbd0562b1


Smart Group

Create a new Smart Group which references your Extension Attribute, with an Operator of after (yyyy-mm-dd) and the year, month and day of your installer package:

440ee95c1298469c9e4ba20191d1b824

Each time you re-deploy your installer package, remember to update the value in the Smart Group.


Possible Gotchas

While the Extension Attribute includes the file modification time, the Smart Group apparently does not. If you're iterating multiple times on the same day, please plan accordingly.

0 REPLIES 0