/build/static/layout/Breadcrumb_cap_w.png

How do I run a a shell script as the logged in user

The mac agent runs under the sudo context.  How can I run a script as the current logged in user on a mac.  

0 Comments   [ + ] Show comments

Answers (3)

Posted by: jknox 9 years ago
Red Belt
0
Something like this might work too depending on what you need to do (Courtesy of macdude):

#!/bin/bash

CurUser=`/usr/bin/users`

PrefDir=/Users/$CurUser/Library/Preferences

/usr/bin/defaultswrite $PrefDir/com.apple.finder CreateDesktop -bool FALSE ## Command to effectCurrent User

 

/usr/bin/killallFinder


Posted by: vjaneczko 10 years ago
9th Degree Black Belt
0
What agent do you mean?
Posted by: SMal.tmcc 9 years ago
Red Belt
0
it would be something like

runuser -l  userNameHere -c 'command'
No password is required to use runuser command and it must be run by root user only.

Options

  1. The -l option : Make the shell a login shell, uses runuser-l PAM file instead of default one.
  2. The -g group : Specify the primary group.
  3. The -G group : Specify a supplemental group.
  4. The -c COMMAND : Pass a single COMMAND to the shell with -c.
  5. --session-command=COMMAND : Pass a single COMMAND to the shell with -c and do not create a new session.
  6. -m : Do not reset environment variables.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ