Overview
The script below will create a LaunchDaemon and Bash script to run Recon at the next reboot.
We've found this helpful with OS upgrade policies which tend to ignore (or fail) when "Maintenance > Update Inventory" is included.
Background
We use Deploying OS X v10.7 or Later with the Casper Suite as a guide for our users to upgrade their operating system via Self Service.
After the installer is cached, in a separate policy, we prompt users to visit Self Service and actually run the OS upgrade. The policy then updates inventory.
Including "Maintenance > Update Inventory" in the OS installation policy proved problematic and after a sucessful OS upgrade via Self Service, the JSS would have stale inventory data and end-users would be again prompted to install the OS upgrade they ran the day before.
Script
Note: Search for /path/to/client-side/ and replace with the appropriate path.
#!/bin/bash
####################################################################################################
#
# ABOUT
#
# Creates a Launch Daemon to run a Recon at next Reboot
#
####################################################################################################
#
# HISTORY
#
# Version 1.0, 10-Nov-2016, Dan K. Snelson
#
####################################################################################################
# Import client-side functions
source /path/to/client-side/functions.sh
####################################################################################################
# Variables
plistDomain="com.company" # Hard-coded domain name (i.e., "com.company")
plistLabel="reconAtReboot" # Unique label for this plist (i.e., "reconAtReboot")
plistLabel="$plistDomain.$plistLabel" # Prepend domain to label
ScriptLog "##############################"
ScriptLog "### Recon at Reboot Create ###"
ScriptLog "##############################"
# Create launchd plist to call a shell script
ScriptLog "* Create the LaunchDaemon ..."
/bin/echo "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${plistLabel}</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>/path/to/client-side/scripts/reconAtReboot.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>" > /Library/LaunchDaemons/$plistLabel.plist
# Set the permission on the file
ScriptLog "* Set LaunchDaemon file permissions ..."
/usr/sbin/chown root:wheel /Library/LaunchDaemons/$plistLabel.plist
/bin/chmod 644 /Library/LaunchDaemons/$plistLabel.plist
/bin/chmod +x /Library/LaunchDaemons/$plistLabel.plist
# Create reboot script
ScriptLog "* Create the script ..."
/bin/echo "#!/bin/sh
####################################################################################################
#
# ABOUT
#
# Recon at Reboot
#
####################################################################################################
#
# HISTORY
#
# Version 1.0, 10-Nov-2016, Dan K. Snelson
#
####################################################################################################
# Import logging functions
source /path/to/client-side/functions.sh
####################################################################################################
ScriptLog "### Recon at Reboot ###"
ScriptLog " " # Blank line for readability
# Sleeping for 300 seconds to give Wi-Fi time to come online.
ScriptLog "* Pausing Recon at Reboot for five minutes to allow Wi-Fi and DNS to come online ..."
/bin/sleep 300
ScriptLog "* Resuming Recon at Reboot ..."
ScriptLog "* Updating inventory ..."
/usr/local/bin/jamf recon
# Delete launchd plist
ScriptLog "* Delete $plistLabel.plist ..."
/bin/rm -fv /Library/LaunchDaemons/$plistLabel.plist
# Delete script
ScriptLog "* Delete script ..."
/bin/rm -fv /path/to/client-side/scripts/reconAtReboot.sh
exit 0" > /path/to/client-side/scripts/reconAtReboot.sh
# Set the permission on the file
ScriptLog "* Set script file permissions ..."
/usr/sbin/chown root:wheel /path/to/client-side/scripts/reconAtReboot.sh
/bin/chmod 644 /path/to/client-side/scripts/reconAtReboot.sh
/bin/chmod +x /path/to/client-side/scripts/reconAtReboot.sh
ScriptLog "* LaunchDaemon and Script created."
exit 0