Last active
November 23, 2020 21:23
-
-
Save talkingmoose/b14bf522c546c62c007173e2480a1990 to your computer and use it in GitHub Desktop.
Calculate usage in hours for a specific application on a specific Mac using Jamf Pro Application Usage information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# server connection information | |
URL="https://jamfpro.talkingmoose.net:8443" | |
userName="api-auditor" | |
password="P@55w0rd" | |
# app and computer information | |
computerID="2" | |
startDate="2018-12-01" | |
endDate="2019-04-10" | |
applicationName="Google Chrome.app" | |
# API submission command | |
THExml=$( /usr/bin/curl "$URL/JSSResource/computerapplicationusage/id/$computerID/${startDate}_${endDate}" \ | |
--silent \ | |
--user "$userName:$password" \ | |
--header "Accept: text/xml" \ | |
--request GET ) | |
# get pretty XML | |
prettyXML=$( /usr/bin/xmllint --format - <<< "$THExml" ) | |
# get information for specific app | |
parsed=$( /usr/bin/grep -A 2 "$applicationName" <<< "$prettyXML" ) | |
# get information for foreground times for app | |
foreground=$( /usr/bin/grep "foreground" <<< "$parsed" ) | |
numberList=$( /usr/bin/awk -F ">|<" '{ print $3 }' <<< "$foreground" ) | |
# total seconds | |
seconds=$( echo "$numberList" | /usr/bin/awk '{ total += $0 } END { print total }' ) | |
# calculate hours of foreground use of application | |
hours=$( /usr/bin/bc -l <<< "(($seconds/60/60))" ) | |
# count of days between provided dates | |
days=$(($(($(date -d "$endDate" "+%s") - $(date -d "$startDate" "+%s"))) / 86400)) | |
# calculate average hours per day | |
hoursPerDay=$( /usr/bin/bc -l <<< "(($hours/$days))" ) | |
echo "User spent an average of $hoursPerDay hours per day over $days days." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment