Run as current user on OS X?

written by d.limanov

I apologize in advance if this is trivial, but I can’t seem to find the ability to run things interactively under the context of currently logged on user. Kind of like ‘runascurrentuser’ utility in Windows version of TEM.

Thanks much!

written by Lee Wei

I don’t have direct experience with this, but I suspect it is easier on Mac OS X compared with Windows.

The Agent is running as root, so all you have to do is to “su” (switch user) to another user id.

For example:

wait su {name of current user} -c [you commands]

Lee Wei

written by aovictor

Just to clarify, if I wanted to install a current package it would be:

wait su {name of current user} -c installer -pkg “__Download/package.pkg” -target /

However, running this only gives back an exit code=1 and package is not installed.

written by jgstew

That would try to install the package as the current user, which would only work if the current user has the correct permissions to actually do the install. It would also only work if there is a user logged in at the time.

Normally this is not how you would install something unless there was something odd about the package that required it to run as the current user.

written by aovictor

Correct, I am trying to get the installer to run this particular pkg as there are some components that will need to run as user. I ensured that the package had full perms to read write and execute. Additionally, all of our users have local admin rights.

I usually do not like to go this method but the installer I have right now is made for ARD but I am trying to use BigFix to push it out. IE - installing as root will give root full functionality but not all the users.

In the past, I have gone back to the vendor to have them re-make the packge. However, this becomes daunting because each subsequent update will require me to go back to the vendor as well.

That is why I am trying to find a way to run as current user.

written by jgstew

Did you try getting the package to install using SU in the terminal before trying in the IEM console?

written by aovictor

I was able to successfully install it by running:

su root

Then running the installer command from terminal as root yield a positive result.

Additionally, running sudo installer also works.

It is only when I run it through big fix, that it fails.

written by jgstew

I don’t mean to run it as “su root” in the terminal, I mean run it as "su " in the terminal.

Then in bigfix run it as "su " like:

wait su {name of current user} -c

or

wait su -c

written by aovictor

su -c installer /path/to/pkg -target /

  • yields syntax error due to the -c

su installer /path/to/pkg -target /

  • yields “cannot execute binary file”

wait su {name of current user} -c installer /path/to/pkg -target /

  • yields Exit code 1 and nothing installed. {name of current user} does correctly identify the user.

wait su -c

  • Is not going to work since I will not manually input 7000 different users into the field.

written by aovictor

Upon further investigation, I was able to run the following command from root as the current user successfully from terminal:

su -c ‘sudo installer -pkg /path/to/pkg -target /’

I was only able to do this after editing the /etc/sudoers file with the following line:

ALL=(ALL) NOPASSWD: /usr/local/installer

However, after applying those changes to my big fix actions, I get an exit code =2 for:

wait su
{name of current user}
-c ‘sudo installer -pkg /path/to/pkg -target /’

or

wait su
{name of current user}
-c ‘sudo /usr/sbin/installer -pkg /path/to/pkg -target /’

Not sure why its kicking back a exit code =2 / unknown command.

[THREAD TIMEWARP]

I came upon this thread while trying to use override=wait runas=currentuser on OS X. I was trying to execute launchctl as the current user, but it failed. I wound up using:

   wait su -l {name of logged on user} -c "/bin/launchctl load -F /Llibrary/LaunchAgents/com.foo.plist"