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)
Please log in to answer
Posted by:
jknox
10 years ago
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:
SMal.tmcc
10 years ago
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
- The -l option : Make the shell a login shell, uses runuser-l PAM file instead of default one.
- The -g group : Specify the primary group.
- The -G group : Specify a supplemental group.
- The -c COMMAND : Pass a single COMMAND to the shell with -c.
- --session-command=COMMAND : Pass a single COMMAND to the shell with -c and do not create a new session.
- -m : Do not reset environment variables.