1 |
JimD schreef: |
2 |
> I have been using Linux for a number of years and the one "trick" I |
3 |
> have never read how to do is something like: |
4 |
> |
5 |
> sudo echo "app-portage/porthole ~*" >> /etc/portage/package.keywords |
6 |
|
7 |
Well this one I do with a set of revised command nicked from the list, |
8 |
entered into ~/.bashrc, and requiring that |
9 |
|
10 |
1) "su" is one of the commands that you are allowed to execute via sudo |
11 |
|
12 |
2) you are exempted from needing to enter a password for 'sudo su': |
13 |
|
14 |
addkey(){ |
15 |
sudo su -c "echo $* >> /etc/portage/package.keywords" |
16 |
} |
17 |
|
18 |
adduse(){ |
19 |
sudo su -c "echo $* >> /etc/portage/package.use" |
20 |
} |
21 |
|
22 |
addmask(){ |
23 |
sudo su -c "echo $* >> /etc/portage/package.mask" |
24 |
} |
25 |
|
26 |
addunmask(){ |
27 |
sudo su -c "echo $* >> /etc/portage/package.unmask" |
28 |
} |
29 |
|
30 |
The general idea being that a) sudo seems to be a bit weird; even though |
31 |
it allows you to perform operations as if you are root, it doesn't do so |
32 |
by pretending that you _are_ root, so you still couldn't write to the |
33 |
/etc/portage/package.* files; b) su does pretend you are root, but "su" |
34 |
alone only just re-logs you in, rather than actually allowing you to |
35 |
execute a command-- unless you use the "-c" switch. su -c then says, |
36 |
"whatever follows this switch is a command that you should execute as |
37 |
root". But of course, since "echo $* (where $* stands for "what I typed |
38 |
after addkey") >> /etc/portage/package.* is a complex command, |
39 |
containing spaces, the syntax of the command following sudo su -c needs |
40 |
to be quoted. |
41 |
|
42 |
|
43 |
> |
44 |
> Another one I always wanted to know if it is possible is: |
45 |
> |
46 |
> sudo > /var/log/foo.log |
47 |
|
48 |
I'm sure it is, with a bit of creativity, though I honestly don't know |
49 |
what your intention is in any case, since this looks to me like you're |
50 |
logging the output of the sudo command to foo.log (but since there is no |
51 |
output really to typing 'sudo', I have no idea what result you might |
52 |
expect). |
53 |
|
54 |
Anyway, hope this is to some degree helpful; what you most likely want |
55 |
to do is read up on bash scripting to understand how to chain the |
56 |
commands that do what you want to get done with sudo. Depending on your |
57 |
goals, you might also consider aliasing (alias etc-update="sudo |
58 |
etc-update"), and fine-tuning your visudo to allow you to run specific |
59 |
apps with sudo, preferably without a password, since if you have to type |
60 |
the password everytime you want to do sudo emerge, you might as well |
61 |
just su, imo. |
62 |
|
63 |
Good luck, |
64 |
Holly |
65 |
-- |
66 |
gentoo-user@g.o mailing list |