Updating User and Location

jamflover
New Contributor

Hello all,

I'm trying to see if there is a way to automatically update user & location field based on the user's login. We currently have Jamf Connect setup and wanted to know if there is a way to get the logged in user to appear in the "email address" or "full name" of the user & location field. Our main goal is here to identify and tie a device to the user using it within the organization. Thanks in advance for any guidance here. 

9 REPLIES 9

jamf-42
Valued Contributor II

you can use recon and parse values as required.. 

Capture 2023-08-07 at 18.18.51.png

Thanks for your reply!

 

How do I make this change?

jamf-42
Valued Contributor II

this gives you logged in user

logdinuser=$(/usr/bin/stat -f%Su /dev/console)

then parse this to a recon with what-ever tag you require..

jamf recon -endUserName "$logdinuser"

 script in policy or files and processes 

I have the below script currently and it is only listing a username as "root" but there is no account called root. It should be a UPN that is logged into the account using Jamf connect.

 

# Get the logged in users username
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

echo "Running recon for $loggedInUser `date`..."

# Run recon, submitting the users username which as of 8.61+ can then perform an LDAP lookup
jamf recon -endUsername $loggedInUser

echo "Finished running recon for $loggedInUser `date`..."

jamf-42
Valued Contributor II

all scripts / file and processes run as root..  the /bin/stat works.. 

 also in case you have funky users names.. use "$variable" just in case.. 

Thanks, I've also tried this but nothing is populating under the username field. 

stevewood
Honored Contributor II
Honored Contributor II

Since you are using Jamf Connect you can grab the exact UPN of the user that is logged in from the state plist file in the user's home folder:

 

/Users/<user>/Library/Preferences/com.jamf.connect.state.plist

 

Couple that with the method to grab logged in user and you get something like:

 

loggedInUser=$(/usr/bin/stat -f%Su /dev/console)
user_upn=$(/usr/bin/defaults read "/Users/$loggedInUser/Library/Preferences/com.jamf.connect.state.plist" UserUPN)
jamf recon -endUsername $user_upn

 

You can set that to run each login via a LaunchDaemon, OR, you can use the Login Script features of Jamf Connect: https://learn.jamf.com/bundle/jamf-connect-documentation-2.22.0/page/Login_Window_Preferences.html

As always, test, test, test, test.... and test some more.

jamflover
New Contributor

Hi @stevewood ,

Thanks for sending this information, I have this mentioned script running via Policy on my test machine. The username field is still not populating under "user & location" am I doing something wrong? Thanks for all the help!

jamf-42
Valued Contributor II

on a test Mac.. just run the recon -endUsername TESTUSER

and check the record.. if that works, something wrong with the code getting the user name.. 

add

set -x 

after the shebang (#!/bin/sh) to see full output in the policy script log.

 

tested: 

Capture 2023-08-08 at 17.02.29.png

Capture 2023-08-08 at 17.02.35.png