Jamf Pro Extension Attributes – Important Dates

With extension attributes in Jamf Pro, an administrator is able to collect extra information about a computer or device whenever inventory is collected. These extra bits of information can be used to generate reports or smart groups based on the values of these attributes. For computers, these attributes can be manually inputted with a text field, generated using a pop-up menu, pulling in attributes from LDAP (if LDAP is configured), or using a script to populate the attribute. Each of these scripts will be using ‘script’ as the input type and ‘Date’ as the data type.

In this post we will look at 3 different extension attributes related to date/time that a Jamf Pro administrator may consider important. These attributes will be:

  • Original OS Install Date
  • OS Update Date
  • Last Reboot Date

These attributes can then be used in Jamf Pro to create Smart Groups like ‘Computers that have not rebooted in 31 days” or “OS Installed over a year ago”, or however else an admin would use this information. Anyway, let’s get into it.

An administrator may want to know when the last time a computer had a clean OS install. This may be helpful in education settings where an annual refresh of computers is required. This extension attribute looks at the AppleSetupDone file to find the last modification date in epoch time, then converts that out to a date/time that is readable by Jamf Pro and can be used with the date/time data type. (OS Install Date.sh – GitHub)

#!/bin/bash

# Returns the orignial install date of macOS
#
# Created 08.30.2022 @robjschroeder

##################################################

# Get original macOS Install Date in epoch time
originDate=$(/usr/bin/stat -f "%B" /var/db/.AppleSetupDone)

# Convert the epoch time into a formatted time
formattedTime=$(date -jf %s $originDate "+%F %T")

# Print the results
echo "<result>${formattedTime}</result>"

exit 0

With our second attribute, we are going to grab the date of the last OS update/upgrade. This script will look for our st_birthtime stat then convert that to a date/time format that Jamf Pro can use for our date/time data type. (OS Upgrade Date.sh – GitHub)

#!/bin/bash

# Returns the last OS update/upgrade date of macOS
#
# Created 08.30.2022 @robjschroeder

##################################################

# Evaluate the status in shell output
eval $(/usr/bin/stat -s /)

# Convert st_birthtime from epoch to a formatted time
formattedTime=$(/bin/date -jf %s "$st_birthtime" "+%F %T")

# Print the results
echo "<result>${formattedTime}</result>"

exit 0

Lastly, we may want to know the last time a computer actually rebooted. With this we won’t have to ask “Have you tried rebooting your computer?”, we will already know because it will be tracked in Jamf Pro. (Last Reboot.sh – GitHub)

#!/bin/bash

# Get boottime in epoch time, convert to Jamf Pro 
# formatted time and make an extension attribute
#
# Updated: 2.23.2022 @robjschroeder

##################################################

# Get kernel boot time
bootTime=$(sysctl kern.boottime | awk '{print $5}' | tr -d ,)

# Convert time
formattedTime=$(date -jf %s $bootTime "+%F %T")

# Print the results
echo "<result>${formattedTime}</result>"

exit 0

Thanks for checking it out!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: