Skip to main content
Solved

Script running su "$currentuser"

  • February 6, 2023
  • 3 replies
  • 83 views

DBrowning
Forum|alt.badge.img+24

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/

 

3 replies

Forum|alt.badge.img+12
  • Valued Contributor
  • 359 replies
  • February 6, 2023

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


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • Answer
  • February 6, 2023

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
  • 132 replies
  • February 8, 2023

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