Holly Bostick wrote:
> JimD schreef:
>> I have been using Linux for a number of years and the one "trick" I
>> have never read how to do is something like:
>>
>> sudo echo "app-portage/porthole ~*" >> /etc/portage/package.keywords
>
> Well this one I do with a set of revised command nicked from the list,
> entered into ~/.bashrc, and requiring that
>
> 1) "su" is one of the commands that you are allowed to execute via sudo
>
> 2) you are exempted from needing to enter a password for 'sudo su':
>
> addkey(){
> sudo su -c "echo $* >> /etc/portage/package.keywords"
> }
What's the use of su here? I don't understand.
What's happening is, that a root process executes
su -c "echo $* >> /etc/portage/package.keywords"
But why switch user from root to root to execute
echo $* >> /etc/portage/package.keywords
I don't understand that. Please explain.
> The general idea being that a) sudo seems to be a bit weird; even though
> it allows you to perform operations as if you are root, it doesn't do so
> by pretending that you _are_ root,
Uh? What are you talking about? The command is run with root
rights. If you use "sudo -H", even $HOME is set to ~root.
> so you still couldn't write to the
> /etc/portage/package.* files;
Yes, you can. The error is, that with
sudo echo blah >> file
Here the NORMAL USER does ">> file", *NOT* the root
echo process!
Have a read in your shell manpage.
> b) su does pretend you are root,
What do you mean with that?
>> Another one I always wanted to know if it is possible is:
>>
>> sudo > /var/log/foo.log
>
> I'm sure it is, with a bit of creativity, though I honestly don't know
> what your intention is in any case, since this looks to me like you're
> logging the output of the sudo command to foo.log (but since there is no
> output really to typing 'sudo', I have no idea what result you might
> expect).
A truncated file is to be expected, as that's what's happening
when you do
> filename
> Anyway, hope this is to some degree helpful; what you most likely want
> to do is read up on bash scripting to understand how to chain the
> commands that do what you want to get done with sudo.
Yep.
Alexander Skwar
--
Keep brain from freezing.
-- Homer Simpson
Simpson and Delilah
--
[email protected] mailing list