How long recon took to run

swapple
Contributor III

I have had some users complain that their Mac is running slowly and have noticed that recon can take different times to run on different Macs. To help measure it, I put my novice script writing skills to work and came up with a script

#!/bin/bash

start=$(date +%Y-%m-%d)
echo "$start Recon Starting" >>/var/log/jamfReconTime.log
now=$(date +%s)
jamf policy
jamf recon
later=$(date +%s)
echo "Took $((later-now)) seconds" >>/var/log/jamfReconTime.log
end=$(date +%Y-%m-%d)
echo "$end Recon Ending" >>/var/log/jamfReconTime.log
echo $((later-now)) > /var/log/reconTime.txt

I then follow it up with an EA that returns an integer

#!/bin/bash

if [ -f "/var/log/reconTime.txt" ]; then
    time=$(cat /var/log/reconTime.txt)
    echo "<result>$time</result>"
else
    echo "<result>0</result>"
fi

Please note that this only captures the time it took for the previous recon to run since it needs recon to report the time to the EA and the time is not calculated until the recon is completed.
But, this does give me the sense for when some recons take 45 seconds to complete and another may take 600 seconds to complete, perhaps the few that are 600 seconds may need some attention from our support team (enter smart group notifications plus a log to see the history of recon time).

So now, instead of ticking the "Update inventory" box, I just run the above script to capture the info. I am assuming that I am getting the same result of "update inventory" by just running a recon.
Use at your own risk, your milage may vary.

1 REPLY 1

thoule
Valued Contributor II

FYI, using the 'time' command can simplify things for you. time jamf recon 2>&1|tail -1 > /tmp/reconTime.txt

Time will output runtime after jamf runs. We only want the last line, not the recon output, then dump that in your temp file.