Created
February 6, 2019 05:07
-
-
Save talkingmoose/8e3ed2977691afdda965b95bd5f8bb34 to your computer and use it in GitHub Desktop.
Returns list of macOS users with active Personal OneDrive syncing.
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 | |
# 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