nawerwidget.blogg.se

Sudo jamf commands
Sudo jamf commands






sudo jamf commands
  1. SUDO JAMF COMMANDS HOW TO
  2. SUDO JAMF COMMANDS UPDATE
  3. SUDO JAMF COMMANDS MAC

SUDO JAMF COMMANDS MAC

Note: the function, as written above, will simply do nothing when the Mac is sitting at the login window with no user logged in.

sudo jamf commands

# to make the function exit with an error when no user is logged inĪnd then you can use the function like this: runAsUser defaults write orientation left Launchctl asuser "$uid" sudo -u "$currentUser" "no user logged in" Paste this at the beginning of your scripts: # convenience function to run a command as the current user I built a small shell function that I use in many of my scripts.

sudo jamf commands

This is, however, a lot to type and memorize. This works for all commands in all contexts. The good news here is, that you can play it safe and use both at the same time: launchctl asuser "$uid" sudo -u "$currentUser" command arguments So, for most use cases, you want to use the sudo solution but in some you need the launchctl form. Now, the lauchctl asuser works and is required when you want to load and unload LaunchAgents (which run as the user), but it does not seem to work in other contexts any more. This changed at some point during the Mojave release time. It used to be that the sudo solution would not work in all contexts, but the launchctl asuser solution would. The launchctl command uses the numerical user ID instead of the user’s shortname so we need generate that first. The first is with sudo: sudo -u "$currentUser" defaults write orientation left There are two ways to run a command as the current user. This is the Posix sh compatible syntax, which will also run with bash or zsh. This will return the currently logged in user or loginwindow when there is none. Getting the current user in macOS – UpdateĬurrentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ ' ).Get Current User in Shell Scripts on macOS.

SUDO JAMF COMMANDS HOW TO

I have written a few posts about how to determine the currently logged in user from shell scripts and will use the solution from those: In many cases the answer is the user that is currently logged in. Then the problem is as which user you want to run as. To get the correct behavior, you need to run the command as a user. This is probably not what you intended to do. Then it will write this preference into root’s home directory in /var/root/Library/Preferences/. When your script, executed by your management system, is running as root and contains this command: defaults write orientation left However, some commands need to be run not as root, but as the user.įor example, the defaults command can be used to read or set a specific setting for a user. The pre– and postinstall scripts in installation packages (pkgs), the agent for your management system, and scripts executed as LaunchDaemons all run with root privileges. The good news here that many of the management tools we can use to run scripts on clients already run with root privileges. Rather than keep modifying the older post, I decided to make this new one.Īs MacAdmins, most of the scripts we write will use tools that require administrator or super user/root privileges. macOS has changed and I had a few things to add.

SUDO JAMF COMMANDS UPDATE

This post is an update to an older post on the same topic.








Sudo jamf commands