Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created February 6, 2019 05:07
Show Gist options
  • Save talkingmoose/8e3ed2977691afdda965b95bd5f8bb34 to your computer and use it in GitHub Desktop.
Save talkingmoose/8e3ed2977691afdda965b95bd5f8bb34 to your computer and use it in GitHub Desktop.
Returns list of macOS users with active Personal OneDrive syncing.
#!/bin/bash
# get list of user home folders of users with UIDs over 500
userList=$( dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }' )
# get current epoch time
rightNow=$( /bin/date "+%s")
# recurse through user list
for aUser in $userList
do
# read the LastRefresh line from the ClientPolicy.ini file
echo "Getting ClientPolicy.ini for user $aUser"
lastRefresh=$( sudo -Hu "$aUser" bash -c '/bin/cat "$HOME/Library/Application Support/OneDrive/settings/Personal/ClientPolicy.ini" 2> /dev/null | grep LastRefresh' )
# list user as active if the last refresh was less than 24 hours (86400 seconds) ago
if [ $((rightNow-lastRefresh)) -lt 86400 ]; then
activeUsers="$aUser $activeUsers"
echo "Active user: $aUser"
fi
done
echo "<result>$activeUsers</result>"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment