Posted on 04-12-2022 09:46 AM
Hey all!
What is a great ext attribute to determine which user is most recently logged in or currently logged in? I'm curious as we use the one provided in a JAMF repository and has worked fairly solidly for us, but wondering if there are any pitfalls to using this.
#!/bin/sh
lastUser=`/usr/bin/last -1 -t console | awk '{print $1}'`
if [ $lastUser == "wtmp" ]; then
echo "<result>No logins</result>"
else
echo "<result>$lastUser</result>"
fi
Posted on 04-12-2022 11:32 AM
lastUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
Posted on 04-12-2022 02:28 PM
My current Extension Attribute is below, have not seen any issues with it so far.
#!/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
Posted on 04-13-2022 11:18 AM
Thanks all! I'm going to give those a shot, actually have a similar script in our server utilizing that same defaults read option. As I've said, the original one I posted has been working pretty well, but sometimes gives us some "no logins" on computers where the defaults read one will work better and give us an output. appreciate it!