Skip to main content
Solved

Get Logged In Local User with Script


Forum|alt.badge.img+5

I am writing a quick script to delete a file from our users computers. We have Jamf Connect on all computers currently.

I'm using this script to get the logged in user:

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

This used to work for us but now that we are on Jamf Connect it just shows the IDP user, not the local user. I need the local user in the variable because that is actually where Documents are stored for the user.

Any way to extract the actual Local account that the user is logged into and avoid the IDP user?

Best answer by jamf-42

healthcareaa wrote:

Not through Jamf because Jamf runs as root


Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

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

View original
Did this topic help you find an answer to your question?

5 replies

jamf-42
Forum|alt.badge.img+17
  • Esteemed Contributor
  • 741 replies
  • August 1, 2023

does this work? 

/usr/bin/stat -f%Su


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 26 replies
  • August 1, 2023
jamf-42 wrote:

does this work? 

/usr/bin/stat -f%Su


Not through Jamf because Jamf runs as root


jamf-42
Forum|alt.badge.img+17
  • Esteemed Contributor
  • 741 replies
  • Answer
  • August 1, 2023
healthcareaa wrote:

Not through Jamf because Jamf runs as root


Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

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


Forum|alt.badge.img+5
  • Author
  • Contributor
  • 26 replies
  • August 1, 2023
jamf-42 wrote:

Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

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


This worked, thank you!


Forum|alt.badge.img
jamf-42 wrote:

Yes... that was more to test the result returned is what you were after.. I use this in JAMF scripts.. and it works?

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


Thank you, it worked for me too.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings