User Environment..

Dana Kaempen decay at
Thu Jun 14 16:32:09 EDT 2001

Mamnoon. Ovace wrote:
> In addition to running a command as a different user, I need to be able to
> load that users environment before the command can be run.
> I need to use something analogous to "su - <user> -c <command>" , currently
> when I run "sudo -u <user> <command>" the result is similar to running "su
> <user> -c <command>"..
I ran into a similar difficulty using cron, until I realized that cron doesn't do an "su - <user>" but instead does an "su <user>"; to solve this, I manually dot in the user's environment (.profile) and all the jobs then run perfectly.  The only thing to watch out for is if the user has their env further customized via .kshrc or similar; although any environment settings *should* be in the .profile, I've seen people do it otherwise.   Try to substitute as follows:

	Before:  command
	After :  . ~<user>/.profile; command

You may want to manually expand the user's home dir instead of using the ksh shorthand (~<user>) above.  Once the user's profile is added into the environment of the shell you're spawning, the command should react the same way as if the user was running it from a terminal.  **NOTE:  If there's anywhere in "command" which normally takes any user input (standard in), make sure to code around that using tty to test for an interactive environment.


mailto:decay at
"Keep the wheels rolling." - Anonymous traffic prophet

More information about the sudo-users mailing list