pushing scripts as user rather than root?

AdamH
New Contributor II

Does anyone have a way to run a script on a remote computer via casper as the logged-in user?
I'm trying to quit the Junos Pulse tray in the menu bar so that the connection URL can be updated. Although locally I have no problem using LAUNCHCTL UNLOAD ... to unload it to make it quit, if I use the same command in a policy, it doesn't work because that plist isn't active under the root user.
I'v also run into other situations where it would be good to run a script as the logged in user rather than root before as well.

is there way?

3 REPLIES 3

rockpapergoat
Contributor III

the pulse client includes a method for importing a config file. if you do this, you shouldn't need to kill the menu bar app.

for instance, if you drop the config file under /etc, you can do this:

/Applications/Junos Pulse.app/Contents/Plugins/JamUI/jamCommand -importFile /private/etc/configfile.jnprpreconfig

that will update the connection url.

acdesigntech
Contributor II

Casper can run scripts in the user context by using the su $3 command. su for switch user, $3 is the username of the current console user.

Careful though, unless you are running a POLICY, the UID of the casper admin will not be 0, and you will be prompted for a password when invoking su. Only root can su to any other user account with no password.

Use the -c option to run only a single command as a particular user

sean
Valued Contributor

You need to tell launchctl what the user PID is of the current loginwindow console, so you'll need something like:

userPID=`ps -ef | grep "loginwindow console" | grep -v grep | awk '{print $2}'`
launchctl bsexec $userPID su $3 -c 'launchctl unload [the thing you want to unload]'