Skip to main content
Solved

Script running su "$currentuser"

  • Feb 6, 2023 3:54 PM UTC
  • 3 replies
  • 213 views

DBrowning
Forum|alt.badge.img+26

I have a script that is running a lot of commands starting with 

su "$currentuser" -c


When the policy is run locally or via Self Service the script runs as expected.  When I let it run via check-in, all the lines that start with the above command do not run.  Any ideas?

Best answer by mm2270

There is a difference between the natural Jamf check-in that gets started via the LaunchDaemon, versus a manual check-in or policy execution (Self Service, doing sudo jamf policy, etc.) The former gets executed entirely in a root context, whereas the latter ones typically run as the user with elevated rights.

All this is to say, I've seen this type of problem before. What typically has worked for me is to use the launchctl asuser syntax you can find here:
https://scriptingosx.com/2020/08/running-a-command-as-another-user/

 

View original

3 replies

Forum|alt.badge.img+12
  • Valued Contributor
  • Feb 6, 2023 4:40 PM UTC

Are you sure that there is always a currentuser during checkin?


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • Answer
  • Feb 6, 2023 4:51 PM UTC

There is a difference between the natural Jamf check-in that gets started via the LaunchDaemon, versus a manual check-in or policy execution (Self Service, doing sudo jamf policy, etc.) The former gets executed entirely in a root context, whereas the latter ones typically run as the user with elevated rights.

All this is to say, I've seen this type of problem before. What typically has worked for me is to use the launchctl asuser syntax you can find here:
https://scriptingosx.com/2020/08/running-a-command-as-another-user/

 


piotrr
Forum|alt.badge.img+8
  • Contributor
  • Feb 8, 2023 12:24 PM UTC

If you echo currentuser you might notice that it's root.