Gentoo Archives: gentoo-user

From: Daniel da Veiga <danieldaveiga@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sudo echo
Date: Thu, 23 Mar 2006 22:53:59
Message-Id: 342e1090603231351u53fc4467y914e5a09af1432aa@mail.gmail.com
In Reply to: Re: [gentoo-user] sudo echo by Holly Bostick
1 On 3/23/06, Holly Bostick <motub@××××××.nl> wrote:
2 > JimD schreef:
3 > > I have been using Linux for a number of years and the one "trick" I
4 > > have never read how to do is something like:
5 > >
6 > > sudo echo "app-portage/porthole ~*" >> /etc/portage/package.keywords
7 >
8 > Well this one I do with a set of revised command nicked from the list,
9 > entered into ~/.bashrc, and requiring that
10 >
11 > 1) "su" is one of the commands that you are allowed to execute via sudo
12 >
13 > 2) you are exempted from needing to enter a password for 'sudo su':
14 >
15 > addkey(){
16 > sudo su -c "echo $* >> /etc/portage/package.keywords"
17 > }
18 >
19 > adduse(){
20 > sudo su -c "echo $* >> /etc/portage/package.use"
21 > }
22 >
23 > addmask(){
24 > sudo su -c "echo $* >> /etc/portage/package.mask"
25 > }
26 >
27 > addunmask(){
28 > sudo su -c "echo $* >> /etc/portage/package.unmask"
29 > }
30 >
31 > The general idea being that a) sudo seems to be a bit weird; even though
32 > it allows you to perform operations as if you are root, it doesn't do so
33 > by pretending that you _are_ root, so you still couldn't write to the
34 > /etc/portage/package.* files; b) su does pretend you are root, but "su"
35 > alone only just re-logs you in, rather than actually allowing you to
36 > execute a command-- unless you use the "-c" switch. su -c then says,
37 > "whatever follows this switch is a command that you should execute as
38 > root". But of course, since "echo $* (where $* stands for "what I typed
39 > after addkey") >> /etc/portage/package.* is a complex command,
40 > containing spaces, the syntax of the command following sudo su -c needs
41 > to be quoted.
42 >
43 >
44 > >
45 > > Another one I always wanted to know if it is possible is:
46 > >
47 > > sudo > /var/log/foo.log
48 >
49 > I'm sure it is, with a bit of creativity, though I honestly don't know
50 > what your intention is in any case, since this looks to me like you're
51 > logging the output of the sudo command to foo.log (but since there is no
52 > output really to typing 'sudo', I have no idea what result you might
53 > expect).
54 >
55 > Anyway, hope this is to some degree helpful; what you most likely want
56 > to do is read up on bash scripting to understand how to chain the
57 > commands that do what you want to get done with sudo. Depending on your
58 > goals, you might also consider aliasing (alias etc-update="sudo
59 > etc-update"), and fine-tuning your visudo to allow you to run specific
60 > apps with sudo, preferably without a password, since if you have to type
61 > the password everytime you want to do sudo emerge, you might as well
62 > just su, imo.
63 >
64 > Good luck,
65 > Holly
66 > --
67 > gentoo-user@g.o mailing list
68 >
69 >
70
71 Holly is right, I had some scripts running the commands I said, heh,
72 what I didn't notice was an alias for sudo as sudo su -c... Sorry for
73 my fast and wrong response... :)
74
75 --
76 Daniel da Veiga
77 Computer Operator - RS - Brazil
78 -----BEGIN GEEK CODE BLOCK-----
79 Version: 3.1
80 GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V-
81 PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++
82 ------END GEEK CODE BLOCK------
83
84 --
85 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] sudo echo Alexander Skwar <listen@×××××××××××××××.name>