Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52243

Re: Using sudo to write to a file as root from a script

References <CA+mfgz3N9++VxoxkPMakMCw7tcYbhPDgpXVtX1mnm5sZy5_xTg@mail.gmail.com>
Date 2013-08-09 14:47 +1000
Subject Re: Using sudo to write to a file as root from a script
From David <bouncingcats@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.384.1376023679.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 9 August 2013 14:11, Adam Mercer <ramercer@gmail.com> wrote:
>
> I'm trying to write a script that writes some content to a file root
> through sudo, but it's not working at all. I am using:

[...]

At a quick glance, I have a couple of suggestions.

>   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]

sudo doesn't work like this. It doesn't read from standard input. You
need to supply the command as an argument to sudo. Get the sudo syntax
correct by learning to use it in a shell (eg terminal running bash )
before trying to use it from python code.

Also, I think that passing the pipe character '|' as an argument to
Popen is not the correct way to use pipes.

So, if you figure out how to use sudo without '|' you will solve both
these issues.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Using sudo to write to a file as root from a script David <bouncingcats@gmail.com> - 2013-08-09 14:47 +1000

csiph-web