Script running su "$currentuser"

DBrowning
Valued Contributor II

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?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

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 solution in original post

3 REPLIES 3

mschroder
Valued Contributor

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

mm2270
Legendary Contributor III

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
Contributor III

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