[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: exit usage



On Thu, Jan 08, 2004 at 11:33:10AM +0100, Florian Ernst wrote:
| Hello Jan!
| 
| -> su -c and sudo for executing a script as a different user
| On Thu, Jan 08, 2004 at 03:17:37AM +0100, Jan Minar wrote:
| >... definitively; but if you really wanted to know how to do it the
| >Wrong Way:
| >
| >Generally, as a Unix process exec's another one (a child), the child
| >can't mess with the parent's internals more than with any other
| >process'--they are just separated processes.  The Unix way to terminate
| >a process without its consent is to kill(8) it.  So the last line of
| >your script would read:
| >
| >	kill -KILL "$PPID"
| >
| >--the shell variable $PPID stores the parent process id.  AFAICT, it's a
| >POSIX-required feature, so your sh(1) should provide it.
| 
| Hmmm, I guess the OP's intentions are as follows:
| - start from the root prompt
| - execute a script as a different user
| - end at the root prompt
| 
| @Rick: Just to make sure, did I understand you correctly?

This was my understanding as well.

| I understand the contents of your, Jan's, posting, but I'm afraid I
| fail to understand how it applies to the OP's intentions (at least the
| way I see them)...
| Can you please hit me gently with a clue bat?

If you are root and you run 'su foo', the current process is now user
foo's shell.  You then execute the script, and the parent process of
the script is foo's shell.  If the script kills the parent process,
then the shell is now dead, and when the script exits, the current
process will be root's shell where su was run.  As Jan said, it is
nasty, but it does sound like it would do what was asked.  (just be
careful to never run that script in any other context, since it kills
its parent!)

Does that help?

-D

-- 
"He is no fool who gives up what he cannot keep to gain what he cannot lose."
    --Jim Elliot
 
www: http://dman13.dyndns.org/~dman/            jabber: dman@dman13.dyndns.org

Attachment: signature.asc
Description: Digital signature


Reply to: