Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Last active December 20, 2024 00:53
Show Gist options
  • Save talkingmoose/9377c1eb0d90ae2d3c3d5fcaf529a393 to your computer and use it in GitHub Desktop.
Save talkingmoose/9377c1eb0d90ae2d3c3d5fcaf529a393 to your computer and use it in GitHub Desktop.
Jamf Pro extension attribute to return date of last reboot. Create the EA with a Data Type of 'date'. This allows a Smart Group to use greater than and less than calculations.
#!/bin/zsh
# get last reboot date and time
lastReboot=$( /usr/bin/last -y reboot )
# extract date and time (e.g. Thu Dec 12 2024 08:35)
rebootTime=$( /usr/bin/awk -F '[[:space:]]{3,}' 'NR==1 { print $2 }' <<< "$lastReboot" )
# convert date and time to ISO date format
lastRebootISO=$( /bin/date -j -f "%a %b %e %Y %H:%M" "$rebootTime" '+%Y-%m-%d %I:%M:00' )
# return result to Jamf Pro
echo "<result>$lastRebootISO</result>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment