I am trying to create an extension attribute to grab the currently logged in user on my student machines. I am using a similar script to the Last User extension script template:
#!/bin/sh
user=`ls -l /dev/console | awk '/ / { print $3 }'`
if [ $lastUser == "" ]; then
echo "<result>Current User</result>"
else
echo "<result>$user</result>"
fi
I have my inventory set to check at login so I can set the extension attribute to the user short name as they sign on. However, when I collect inventory at login, I only get "root" as the currently signed in user. After the user signs in, I can run "sudo jamf recon" from an ssh session as the local admin and it appropriately records the current user in the extension attribute. Why does it show "root" when I run the script at login, vs when I run the script after the user has signed in? Is the inventory collected prior to a user technically being logged in when I have inventory set to collect at login? Is there another way to collect extension attributes outside of an inventory update? I have also tried to create a policy that runs at login, which just issues the command "jamf recon" but I get the same result.
