Is there a better way to detect a machine's primary user? I have an Extension Attribute that will supposedly gather this information. For the most part it does an OK job. But, I always have to go back and clean up after the script because it always lists a random user as being the owner of 15 to 20 machines. I can honestly say I have no idea how this duplication is happening.
Is anyone else having better luck? Are you able to gather Primary User information correctly and accurately?
This is the script I am using to gather the Primary User:
#!/bin/sh
TopUser=$( last -t console | awk '{print $1}' | sort | uniq -c | sort -n | awk 'END{print $NF}' )
echo "<result>$TopUser</result>"
I have also started using a different EA that will display the "Last Logged-on User" to try and match the two. But, that's not really being much help.
Here's the "Last Logged-on User" script:
#!/bin/sh
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
if [ $lastUser == "" ]; then
echo "<result>No logins</result>"
else
echo "<result>$lastUser</result>"
fi
Any help would be greatly appreciated.
Thanks!