shells and pipes
Todd C. Miller
Todd.Miller at courtesan.com
Wed Jun 14 19:32:08 EDT 2000
In message <B04EF180935DD3119A930008C79117A621CC4C at mail.directvgla.com>
so spake "Hanson, James J" (JJHanson):
> 2) Redirects and pipes seem to lose the root permissions, anyway
> around this
Not really. The shell interprets these before sudo sees the command
so the only way to work around it is to wrap the command in a subshell.
Eg. sudo sh -c 'echo foo > bar'
Now, for pipes the situation is not so bad since you can just prefix
both ends of the pipe with sudo, eg.
% sudo tar cf - foo bar glarp | ( cd /home/stuff; sudo tar vxf - )
However, you may find that both sudos are asking for your password at
the same time. You can pre-authenticate via "sudo -v" before running
the command to work around this.
> 3) I have aliases configured to do sudi='sudo -u informix', which seems
> to work fine unless I try to use sudi in a shell script. Am I forced
> to source in this alias with every script I attempt this
I'm afraid so. Of course, you could split out the sudo aliases into
their own file so things are nicely compartmentalized.
More information about the sudo-users