Skip to main content
Question

Current logged in user not working with Extension Attribute?


Forum|alt.badge.img+6

I'm running into an issue with a Python script where if I run it locally (on any machine) it outputs the correct result. Essentially the script is just looking for the existence of a couple .plist files as of now.


However, when I upload the script into an extension attribute, something goes wrong with getting the current logged in user and messes with the filepath I'm pulling in the script. Any ideas what might be causing this? I'm assuming it must be pulling 'root' as the user when run by jamf or something? Is there a way around this?

3 replies

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • March 15, 2019

@jrogersnh Post the entire script here using the >_ button. I could easily rewrite this in bash for you to test.


Forum|alt.badge.img+16
  • Honored Contributor
  • 403 replies
  • March 17, 2019

@jrogersnh this is because of how you are gathering the current user. When EAs run, they are run as root. Using id in the way you are isn’t getting the active console user, it’s getting the username of the person running the command itself. You should use one of the many ways that are listed on here that gather the active console user. You should also make sure you account for when there is no active user logged into the machine as well.


Forum|alt.badge.img+16
  • Honored Contributor
  • 403 replies
  • March 17, 2019

Since you’re using python, you could use this:

from SystemConfiguration import SCDynamicStoreCopyConsoleUser

username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]
username = [username,""][username in [u"loginwindow", None, u""]]

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